byteblitz icon indicating copy to clipboard operation
byteblitz copied to clipboard

Add support for output redirection to file.

Open noahra opened this issue 2 years ago • 6 comments

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

noahra avatar Jan 03 '24 10:01 noahra

POSIX has isatty(). Some of the libraries used probably implement this feature.

arthurbacci avatar Jan 29 '24 01:01 arthurbacci

Actually it's part of Rust's std :). https://doc.rust-lang.org/std/io/trait.IsTerminal.html

arthurbacci avatar Jan 29 '24 01:01 arthurbacci

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.txt create idk.txt if it doesn't exist and return an error if it does. And echo "idk" | byteblitz be simply invalid?

arthurbacci avatar Jan 29 '24 01:01 arthurbacci

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 avatar Jan 29 '24 17:01 arthurbacci

@arthurbacci The Issue is now updated. I was unclear with my intentions, I hope it is clearer now.

noahra avatar Jan 29 '24 18:01 noahra

ok, I will open a separate issue for the output

arthurbacci avatar Jan 29 '24 18:01 arthurbacci