Skip to content

Instantly share code, notes, and snippets.

@nbareil
Created September 26, 2011 14:04
Show Gist options
  • Save nbareil/1242307 to your computer and use it in GitHub Desktop.
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
#! /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