Created
September 26, 2011 14:04
-
-
Save nbareil/1242307 to your computer and use it in GitHub Desktop.
Takes a huge tarball in input and writes gzipped files in current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env python | |
| import sys, os | |
| import tarfile, gzip | |
| if not len(sys.argv) > 0: | |
| print 'usage: %s huge.tgz' % (sys.argv[0]) | |
| sys.exit(1) | |
| tar = tarfile.open(sys.argv[1]) | |
| for m in tar: | |
| if not m.isfile(): | |
| continue | |
| try: | |
| os.makedirs(os.path.dirname(m.name)) | |
| except: | |
| pass | |
| # Tarball is assumed to be "safe" | |
| # no check is done to assure there is no ../../ member in tar | |
| mgz = gzip.GzipFile(m.name + '.gz', 'w') | |
| fd = tar.extractfile(m) | |
| for line in fd: | |
| mgz.write(line) | |
| mgz.close() | |
| tar.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment