I am looking for a simple way to view the contents (file names) of a .gz archive. I saw that there has been a discussion already on how to do this when using .zip archive. So basically I am looking for the analogue of ZipFile.namelist(), but for .gz archives.
Asked
Active
Viewed 709 times
1
splinter
- 3,727
- 8
- 37
- 82
-
1refer this : https://stackoverflow.com/questions/33592099/how-do-i-list-contents-of-a-gz-file-without-extracting-it-in-python – Adarsh Feb 26 '18 at 08:33
1 Answers
2
.gz files are not, in and of themselves, archives. A .gz file contains a single compressed file. When you decompress foo.bar.gz, you get the file foo.bar. So there's your one name, in the name of the .gz file itself.
You might have a .tar.gz file, which is a TAR (tape archive) file containing a representation of a directory of files, that is then compressed as a single file by gzip. In that case, you would need to use Python's tarfile to read the file and list the contents.
Mark Adler
- 101,978
- 13
- 118
- 158