Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In tar compressed file is there a way to add comment or description [closed]

Tags:

Is a way to add a comment or description in tar file? The idea is to add information without the need of extracting the whole archive - Something super fast, such as "This archive is for blah blah" For example:

tar --comment "This tar us for blah blah" -cjvf mytarfile.tar.bz2 directory_that_I_want_to_compress

UPDATE I found what I want to do using zip and unzip instead. I can store my comment in a file within the zip archive and quickly retrieve that file without the need of extracting the whole archive. Fast.

zip -r my.zip my_dir
unzip -p my.zip my_dir/mycomment.txt
like image 373
RonPringadi Avatar asked Sep 12 '16 19:09

RonPringadi


1 Answers

There is no comment field in the tar format.

You would have to add a file to the tar archive (e.g. a README or COMMENT file).

Adding a file to a compressed tar archive (.tar.bz2 in your example), will not be fast. The most straightforward way would be to decompress, remove the terminating last 1024 bytes of zeros, append the tar header and contents for the final file to add, and then append 1024 bytes of zeros to terminate. Then recompress.

For a .tar.gz, it would be possible to reduce the work to decompressing to find the last deflate block or blocks containing the last 1024 bytes (and then some), and only recompressing those when appending. This would require advanced use of the zlib library, and some understanding of the deflate format. (See gzappend for an example.)

Something similar might be possible with a .tar.bz2, by searching for the last BWT block, and only recompressing that. Again, requiring some intimate knowledge of the compressed data format.

The gzip file format does allow for a comment field in the gzip header, but the bzip2 format does not.

like image 194
Mark Adler Avatar answered Sep 23 '22 17:09

Mark Adler