Why am I getting an error when using tar with brotli for extraction?

0
12
Asked By SillyTuna83 On

I'm trying to use a script to create and extract a tar archive with brotli compression. When I create the archive with the command `tar --create --directory="${HOME}/Desktop/scripts" --file "test.tar.br" --use-compress-program="brotli --quality=6" "test"`, it works fine, and I get a "good" output. However, when I attempt to extract it using `tar --directory="${HOME}/Desktop/scripts" --extract --file "test.tar.br" --use-compress-program="brotli --quality=6"`, I receive an error: "Error opening archive: Unrecognized archive format". Is there a reason why the --use-compress-program option isn't working for extraction? I'm using an Apple M1 Mac Mini with Tahoe 26.1.

3 Answers

Answered By CleverPineapple24 On

It sounds like you're not using the right order for your tar command. When you create or extract a tar file, the `--create` or `--extract` should be the first parameter. Try changing your extract function to:
```bash
if tar --extract --file "test.tar.br" --directory="${HOME}/Desktop/scripts" --use-compress-program="brotli --quality=6";
```
This change should help avoid any issues with how the command is parsed.

Answered By ChillLizard77 On

You really shouldn't specify a compression level when extracting. The `--use-compress-program` option is mainly for creating the archive, not for reading it. If you want to troubleshoot further, you could wrap the brotli command in a script to see how it interacts with tar. The descompression process might require a different flag, something like `-d` depending on how you're using brotli.

Answered By FixItWizard54 On

I ran into a similar issue with extraction on macOS. I discovered that commands like `tar`, `grep`, and `sed` behave differently on macOS because it's based on BSD, not GNU. As a solution, I ended up installing the GNU versions of these commands, which resolved a lot of the inconsistencies. Just make sure to update your paths in `~/.zshrc` to point to the GNU tools.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.