Add support for output redirection to file.
Issue Description:
Feature Request: Output Redirection to file
Background:
Currently, byteblitz allows users to view the binary content of files. However, it cannot directly redirect the output to a file using the standard output redirection operator (>).
Proposed Feature: Implement functionality in byteblitz so that users can redirect the formatted output directly to a target file using the > operator. The expected command structure after implementation would be:
byteblitz -<format> <filename> > output.file
Example:
If a user wants to view the contents of a file named cool.png in hexadecimal , and save the formatted result into output.txt, they could use:
byteblitz -hex document.txt > output.txt
POSIX has isatty(). Some of the libraries used probably implement this feature.
Actually it's part of Rust's std :). https://doc.rust-lang.org/std/io/trait.IsTerminal.html
A question before implementing it:
- Should the contents be held on memory or a temporary file? Or should a file be created in the current directory?
Should
echo "idk" | byteblitz idk.txtcreateidk.txtif it doesn't exist and return an error if it does. Andecho "idk" | byteblitzbe simply invalid?
SUSv1's System Interface Definitions, Issue 4, Version 2 describes the behaviour of /dev/tty for getting access to the terminal to ignore redirections (pipes).
This should be portable to nearly all unix-like systems.
@arthurbacci The Issue is now updated. I was unclear with my intentions, I hope it is clearer now.
ok, I will open a separate issue for the output