Question

Is it possible to list the contents of a LZMA file (.7zip) without uncompressing the whole file? Also, can I extract a single file from the LZMA file?

My problem: I have a 30GB .7z file that uncompresses to >5TB. I would like to manipulate the original .7z file without needing to do a full uncompress.

Was it helpful?

Solution

Yes. Start with XZ Utils. There are Perl and Python APIs.

You can find the file you want from the headers. Each file is compressed separately, so you can extract just the one you want.

OTHER TIPS

Download lzma922.tar.bz2 from the LZMA SDK files page on Sourceforge, then extract the files and open up C/Util/7z/7zMain.c. There, you will find routines to extract a specific archive file from a .7z archive. You don't need to extract all the data from all the entries, the example code shows how to extract just the one you are interested in. This same code has logic to list the entries without extracting all the compressed data.

I solved this problem by installing 7zip (https://www.7-zip.org/) and using the parameter l. For example:

7z l file.7z

The output has some descriptive information and the list of files in the compressed files. Then, I call this inside python using the subprocess library:

import subprocess
output = subprocess.Popen(["7z","l", "file.7z"], stdout=subprocess.PIPE)
output = output.stdout.read().decode("utf-8")

Don't forget to make sure the program 7z is accessible in your PATH variable. I had to do this manually in Windows.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top