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
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.
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.
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
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically