5

I'd like to use brotli to compress a list of files and directories. I'm able to do this with zip running

zip -r  archive.zip *

and I'm looking for a similar command with brotli. I've tried

tar -cf archive.gz * && \
brotli -n -q 11 -o archive.zip archive.gz

but after decompression the zip doesn't have the same structure than with zip.

Guig
  • 9,891
  • 7
  • 64
  • 126

4 Answers4

8

Your second command is actually right. Brotli, like Gzip/Bzip2/etc can only compress a single file.

What you must do is first package all of your files in a tarball:

tar -cvf output.tar /path/to/dir

And then compress the resulting tarball with Brotli:

brotli -j -Z output.tar

Which should leave you with a output.tar.br file (similar to *.tar.gz gzipped tarballs).

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
1

Either of these commands will work to create a brotli compressed tar file without an intermediate tar file:

  1. Directly using tar with the option --use-compress-program
    tar -cvf test-output.tar.br --use-compress-program="brotli -Z" ./my_data_to_compress
    
  2. Piping to brotli
    tar --create --verbose ./my_data_to_compress | brotli --output=compressed_files.tar.br
    
ehiller
  • 1,346
  • 17
  • 32
0

Have you tried Brotli-cli?

This comes with a lot of options to get files compressed using Brotli

alchemist95
  • 759
  • 2
  • 9
  • 26
-1

you can try creating a .tar file instead of .gz

  • Please elaborate, why does that help? – JJJ Mar 25 '19 at 20:01
  • I thought he was trying to compress an already compressed file (gzip), which won't work.. but now I realized he's only naming as .gz (missing z parameter), so it's just a tarball .gz suffixed.. should work – Mateus Velleda Vellar Mar 25 '19 at 20:57