Commit Graph

1 Commits

Author SHA1 Message Date
flos 7ccb6d821f rw: add package 'rw', a Rust analogue of sponge(1)
The current version of `sponge(1)` from moreutils always write to TMPDIR for atomic write, even if we point it to stdout.

This will double the wearout of flash storage if target is stdout, e.g:

   $ wget .... | sponge | sort | rev > filename.txt

the data will got written to flash storage in twice:
`$TMPDIR/spongeXXXX` and sort/rev'd `filename.txt`.

Since on unrooted device `TMPDIR` is usually not a tmpfs, using sponge in similar cases will result in unnecessary wearout of flash storage when:

 - invoke sponge w/o params, or target is stdout
 - end of pipeline point to a file in a filesystem different than TMPDIR resides

In case of the length of input data is prior known or splited to less than available memory, we can use `rw` instead.
2022-08-31 22:23:07 +03:00