Long Story Short

I'm working with Tar archives that contain PNG images in base64 encoding. I would like to use BASH (or whatever else works) to hook into the extraction function of Tar to decode PNG images from base64 encoding to standard PNG encoding after the files are unpacked. A simple cat $input_file | base64 -d >$output_file will successfully decode the images.

Is there a way I can hook into tar -xf so that users do not have to do any (or minimal) extra work to decode the images?

In the GNU Tar documentation I found that there are in fact variables reserved to hold the names of functions I desire to be hooked into various moments in Tar program execution. However, the documentation explains that these variables, along with other variables that can be set to configure Tar, are located in a file named backup-specs. Unfortunately, the path to this file is not given. Further, running sudo find / -name backup-specs tells me that this file is not present on my Ubuntu version 13.04 system.

Background Information not included in the Long Story Short

I've been working on a browser-based (WebGL) particle effect creation application (http://www.particleeffect.org), (https://github.com/cgrabowski/webgl-particle-effect-editor), (https://github.com/cgrabowski/webgl-particle-effect). I've begun to write a client-side-only solution for saving and loading effect data as a tar archive. However, since client-side JavaScript has limited capability to process binary data, the images used as textures in the effect are saved with base64 encoding. I've been able to implement saving effect data as a Tar archive (haven't pushed that to Github yet). However, the images present in said Tar archive cannot be manipulated unless they are decoded from base64 encoding.


You want to use the --to-command option of tar:

tar xf tarfile.tar --to-command='sh -c "mkdir -p $(dirname $TAR_FILENAME) && base64 -d > $TAR_FILENAME"'

This is described in the manual here.

backup-specs is part of the backup system the manual claims is distributed with tar, however my system lacks this and I don't think actually uses it, at least not anymore.

  • 1
    The backup system needs to be installed separately (or enabled with a configure option if you're installing from source.) The debian package name is tar-scripts. – rici Oct 22 '13 at 1:45

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.