sunzip icon indicating copy to clipboard operation
sunzip copied to clipboard

Add "cli callback" for streaming output

Open gizlu opened this issue 3 years ago • 0 comments

Add -c cmd [cmd_arg ...] ; option which, for each extracted file will spawn supplied program, supply decompressed file to its stdin and save its stdout instead of original file. Add -j n option, for specifing count of concurent instances of spawned callbacks

It allows for downloading, unziping and processing files without storing originals on disk

For example:

  • download, unzip and convert pictures from archive to webp, non-picture-files are "destroyed": curl "https://dd.b.pvp.net/latest/set1-lite-en_us.zip" | sunzip -j 4 -c cwebp -quiet -m 5 -o - -- - \;
  • Same, but more elaborate
  • compute checksum of every file in archive: sunzip -c md5sum - \; -j 2 < archive.zip (very likely useless, but nice for testing)

Problems with this patch:

  • sunzip will keep running even if program returns non-zero exit code. Rationale for that is that callbacks often fail with non-zero status if suplied unrecognized file. Maybe I should add flag for not ignoring child's exit code when it is not a problem?
  • It is unix specific. It won't even compile on windows (has it before?). It can be made optional feature disabled on not posix (easy), or ported
  • Cleanup after childs, in case of sunzip failure, is done in quite wishful manner - we assume that single SIGTERM will simply kill them. It should be easily fixable, see comments in bye() implementation
  • We don't handle any timeouts. Should we?

I done this for fun and don't have any particular use case for this (actually, I had, but this was another useless project done for fun), thus i don't have much motivation for polishing this, but I can try if you would be willing to merge this

gizlu avatar Jun 20 '22 17:06 gizlu