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.

1
  • You're right. I forgot. It's PC. I've added the tag now. – typo Oct 30 '17 at 23:09
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.

2
  • Thanks. This gave me the idea to use tar for folders: tar --create --verbose --lzma folder_path/ | wc -c | numfmt --to=iec – typo Sep 24 '19 at 2:22
  • 1
    for big files it is better to pipe to pv -b > /dev/null instead of wc -c – eadmaster Sep 24 '19 at 21:19
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.

3
  • 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 Oct 31 '17 at 2:14
  • @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 Oct 31 '17 at 2:20
  • 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 Oct 31 '17 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.