google / guetzli

Perceptual JPEG encoder
Apache License 2.0
12.9k stars 976 forks source link

Support for stdin/stdout using - as the filename #104

Closed karamanolev closed 7 years ago

karamanolev commented 7 years ago

This a mostly standard feature on many command-line tools that I've used and it would be great if guetzli supported it too. With the current version, passing /dev/stdout for the output file works OK, using /dev/stdin does not due to guetzli trying to seek on it. If the seeks are really needed, I guess even loading the whole input in memory shouldn't be such a problem, due to the already gigantic memory requirements.

fkistner commented 7 years ago

The input file is already completely loaded into memory. Seems to me that fseek is only used to determine the necessary size of the char[] array the file is being read into: https://github.com/google/guetzli/blob/9bfa01f247b24dc45eb61912ec42a9a2b6a4cd95/guetzli/guetzli.cc#L143

Maybe a std::vector plus read loop could fix the problem here?

robryk commented 7 years ago

Yes, something like that should fix this issue. Feel free to send a PR, otherwise I'll do it sometime this week.