0

How to do random file access from a tar archive in java? Using apache-commons-compress tarArchiveInputStream there is no method to get the specific file based on its tarArchiveEntry name. For each query for a file object(bytes[]) it is required to iterate through the whole tar file for every time. How to do an efficient programming with tar archives in such cases?

Arunavo
  • 34
  • 2
  • 8
  • 1
    As any other tool does it: extract the entry, process it, recreate the archive with the new content. – Holger Jun 22 '21 at 11:27
  • Would that be efficient? If a tar file contains 1lakh items then extraction of the tar would incur a huge IO cost and then again that extracted directory need to be deleted. Is this an optimized approach? – Arunavo Jun 22 '21 at 13:32
  • 1
    You don’t need to extract all files. But the way, a tar archive works, there is no way around running through the file until the particular entry is found. Processing them in the order they are actually stored can avoid this. But still, you’d have to get rid of the requirement to have a random access file. – Holger Jun 22 '21 at 14:20
  • So the thing is, suppose I take the previous example of looking up the tar of 1Lakhs of entries, the usual way is to extract the tar content in the local directory and then read the files from there. Now if this is a user desktop application the user might not have adequate storage. – Arunavo Jun 23 '21 at 16:46

1 Answers1

0

Please refer to this earlier case in stackoverflow: How uncompress a specific file from a TAR using apache commons?

OR for better understanding please follow this link: Apache commons

imperial
  • 9
  • 3