Do a compression dry run (i.e., no file output)

1

Is there any way to do a dry run compression to RAR or 7-Zip format? (Command line is fine.) What I'd like to get is an accurate compressed size estimate.

I tried to find an option for it in WinRAR and 7-Zip, even looked at their CL switches, but no luck.

typo

Posted 2017-10-30T21:49:00.777

Reputation: 115

You're right. I forgot. It's PC. I've added the tag now. – typo – 2017-10-30T23:09:20.213

Answers

1

You can use gzip to preview zip compression (deflate) and xz to preview 7zip compression (lzma) like this:

gzip -c $1  | wc -c
xz --format=lzma -c $1  | wc -c

Optionally pipe to numfmt --to=iec to make the bytes count easily readable.

Note that it works only for single files and the count is missing the archive header.

You can find all the binaries needed for Windows in the git sdk package.

eadmaster

Posted 2017-10-30T21:49:00.777

Reputation: 706

Thanks. This gave me the idea to use tar for folders: tar --create --verbose --lzma folder_path/ | wc -c | numfmt --to=iec – typo – 2019-09-24T02:22:20.823

1for big files it is better to pipe to pv -b > /dev/null instead of wc -c – eadmaster – 2019-09-24T21:19:13.177

0

I'm not familiar with WinRAR or 7-Zip but a quick look at WinRAR's online help suggests you can use the -P and -inul flags to direct compressed output to stdout. You can pipe this to the wc utility which is standard on Linux and MacOS and available for Windows as part of the Windows 10 Windows Subsystem for Linux or the GnuWin32 utils (see the textutils package).

For example:

rar -P -inul <rest of WinRAR parameters...> | wc -c

This will return the number of characters (bytes) that the compressed file would have been if it was written to disk.

Mike Fitzpatrick

Posted 2017-10-30T21:49:00.777

Reputation: 15 062

This seems like it will do the trick. Just one thing, though: do I need enough free space for what would be the resulting file, or does stdout flush its buffer continuously as it receives new data? – typo – 2017-10-31T02:14:00.410

@typo, you won't need any disk space. If the parameters are correct, WinRAR will pipe to stdout which is piped to stdin for wc which counts the bytes and discards them. Nothing will be written to disk. – Mike Fitzpatrick – 2017-10-31T02:20:02.003

Hmm, it seems that p command only works for extraction. It's not mentioned in the manual, but it keeps adding ".rar" extension to my selected folder and complaining that it can't find the specified file (when I remove the -inul switch). I also looked up the stdout option in 7-Zip's Help, and while it's available, it only works with xz, gzip, bzip2 and tar formats when used with compression. So I guess I've run out of options. – typo – 2017-10-31T08:22:56.227