Skip to content

Instantly share code, notes, and snippets.

@vsoch
Created December 12, 2018 14:52
Show Gist options
  • Save vsoch/e06a0dc2eb43a72b38db5ee0b5cdd555 to your computer and use it in GitHub Desktop.
Save vsoch/e06a0dc2eb43a72b38db5ee0b5cdd555 to your computer and use it in GitHub Desktop.
Neato! Extract a .tar.gz from a .tar, and read the file content, all in memory
import sys
import tarfile
input_tar = sys.argv[1]
tar = tarfile.open(input_tar, 'r')
for member in tar:
print("Extracting %s" % member.name)
subtar = tarfile.open(mode='r|gz', fileobj=tar.extractfile(member))
for submember in subtar:
print("Found %s!" % submember.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment