google / zopfli

Zopfli Compression Algorithm is a compression library programmed in C to perform very good, but slow, deflate or zlib compression.
Apache License 2.0
3.42k stars 326 forks source link

Support piping input #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For example, it would be nice to be able to do:

    tar -cv foo | zopfli -c > foo.tar.gz

For this example to work, Zopfli would have to support direct input as well 
(not just file names), e.g.

    zopfli -c -s "$(cat foo.txt)"

Original issue reported on code.google.com by mathias@qiwi.be on 29 Apr 2013 at 11:56

GoogleCodeExporter commented 9 years ago
Supporting piping itself is pretty straightforward: if stdin is a tty, then 
handle the shell argument values; if stdin is not a tty, then handle the piped 
content instead.

Original comment by mathias@qiwi.be on 29 Apr 2013 at 11:58

sysadmiral commented 8 years ago

This would be very nice to be able to pipe to zopfli!

Herst commented 8 years ago

It's worth noting that instead of looking at the stdin every time it's also common to accept a special "-" file name which acts as a placeholder for stdin or stdout (depending on the context). Now this isn't perfect (special file names are never good) and it's probably better to have a separate parameter but it goes to show that trying to determine whether the stdin is a tty isn't necessary (and might come with its own downsides).

Herst commented 7 years ago

BTW, a third party solution exists at http://stackoverflow.com/q/38353692/2261442

rspeed commented 7 years ago

@Herst That code writes the streams to temporary files, which isn't really a solution.

Jesin commented 7 years ago

I really prefer using the "-c" flag, like gzip and xz. If it were based on "detecting whether stdin is a tty", that would lead to inconsistent behavior if you try to run a script in the background in certain ways, invoke it from a GUI, etc.