Open montehurd opened 5 months ago
That's what xargs is for.
@ILoveGoulash Not trying to make N calls to it. Trying to let it handle thread spawning
Unless I misunderstand what you are suggesting?
Yes, printf '%s\n' *.png | tr '\n' '\0' | xargs -0 oxipng
is (minus corner cases related to ARG_MAX
) identical to oxipng *.png
.
xargs -n1
is what would make a single call per file.
But well, since oxipng does nothing with its stdin (I think?), it'd be cool to read it and add PNGs to the work queue asynchronously (something xargs can't do).
@montehurd just use fd
:
# files will be processed 1 by 1 (i.e. not in parallel) and oxipng will be multithreaded
fd . --extension png --threads 1 --exec oxipng --preserve --opt max {}
# or with short flags
fd . -e png -j 1 -x oxipng -p -o max {}
# alternatively, run N threads for N files with single-threaded `oxipng`
fd . -e png -x oxipng -t 1 -p -o max {}
If a png paths list could be passed via stdin it would be easier to optimize a subset of a collection of images ( in my use case this subset is unoptimized images ) while still leveraging oxipng's great built-in thread spawning to churn through them efficiently