anycat - general decompressor at command line

This is a micro post about a simple command-line utility that is decompresses several file types and sends them to stdout much like cat. Its' called anycat. The rationale is that in some cases we do not now in advance which file we need to decompress, or we want to test different algorithms. Another usage is in the context of flexible networking tools such as socat.

The source code of this script is on git.

The script invokes the correct decompressing tool using the extension of the input file or by means of an argument. Supported compression formats are: gzip,bzip2,xz,lzma,lz4.

anycat can extract a file contained in a tar or zip archive path; in this case compressed tar files are also supported.

Some examples:

anycat some.lz4 

Decompresses some.lz4 identifying it by the extension

cat some.lz4 | anycat -4 -

Decompresses the stdin content to stdout using an argument (-4) to identify the compression type

anycat -a under/someinside.xml

Extracts the file under/someinside.xml from the zip archive and prints on stdout.

Several extensions are possible:

  • making a native executable in C++ that embeds all compressors, reducing in this way the dependencies. Boost Streams is a good candidate, it supports also lz4 in streaming mode thanks to my fork
  • other compression types

Finally it would be interesting to pass some metadata along the piping mechanism of the shell so that it is possible to take decisions: e.g. passing the name of the decoded file from archive, passing the mime type for dealing with images...


Popular Posts