This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 254
Projects_python gzipstream
Grant Gainey edited this page Dec 12, 2016
·
2 revisions
A streaming gzip handler.
gzipstream.GzipStream extends the functionality of the gzip.GzipFile class to allow the processing of streaming data.
#!/usr/bin/python -u
""" test on huge file which tends to expose "interesting" behavior """
import os
import sys
import time
print "NOTE: intended to be run from the gzipstream directory in CVS"
print
from gzipstream import GzipStream
INPUT = os.path.join(os.path.dirname(sys.argv[0]), 'huge-all-zeros.txt.gz')
BUFSIZE = 1024*16
t0 = time.time()
print "WARNING: This test takes a while to complete as it works on a very"
print " file. It will:"
print " - G*un*zipStream %s and count chars" % repr(INPUT)
print " - compare with a zcat|wc"
print
try:
# python 2.* only
class File(file):
seek = None
fin = File(INPUT, 'rb')
print "Opened file as file object with no seek for a 'socket-like' test."
except:
print "Opened file as a normal file object."
fin = open(INPUT, 'rb')
gzin = GzipStream(fin, 'r')
sys.stderr.write('reading...\n')
x = gzin.read(BUFSIZE)
count = len(x)
while x:
x = gzin.read(BUFSIZE)
count = count + len(x)
print "GzipStream's char count:\n%s" % count
print "'zcat <file> | wc -m' char count:"
os.system('zcat %s | wc -m' % INPUT)
print "They should match."
print 'Elapsed:', (time.time() - t0)/60.0, 'mins'
See http://spacewalk.redhat.com/documentation/python-gzipstream
Follow GitGuide and code is located in directory projects/python-gzipstream/ within checkout. If you run:
tito build --tgz
in that directory you will get latest tar.gz file.
Or download python-gzipstream-1.6.2.tar.gz
Do you want to contribute to this wiki? See page WikiContribute for more info.