Home > Enterprise >  Read .tar entries in a specific order (C#, SharpLibZip)
Read .tar entries in a specific order (C#, SharpLibZip)

Time:02-02

Background

In this website I found several examples for reading a .tar achieve using SharpLibZip.

Question

In my case however I'd like to make sure that entries are read in a specific order based on their names. Is there an easy way to do so?

More details

My .tar archive contains monthly data with per-day files (file-01, file-02, ..., file-31). However, the data provider doesn't seem to pay attention while creating the .tar file and the entries seem to arrive in a random order.

CodePudding user response:

You would need to write your own tar decoder. It is up to you to say if you would consider this to be "easy" or not. The tar format is pretty simple.

You would need to first scan through the tar file to find all the headers, saving the file name and the offset and length of the file data for each. Then you could seek back and forth to the offset of any file to read its contents.

This would be much more difficult if the tar file were compressed, e.g. if it were a .tar.gz file, as opposed to a .tar file.

The tar format is documented here.

  •  Tags:  
  • Related