diff options
author | Guido van Rossum <guido@python.org> | 1998-09-14 16:44:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-09-14 16:44:15 (GMT) |
commit | 4117e5428bf1ff3d26d23bd77472265412473ad9 (patch) | |
tree | d3a38e1c85eb46e5299cec0d5fb358cdc1db28fe /Demo/zlib | |
parent | f9a6d7d49425a04b10e4373077230c6cb93c5817 (diff) | |
download | cpython-4117e5428bf1ff3d26d23bd77472265412473ad9.zip cpython-4117e5428bf1ff3d26d23bd77472265412473ad9.tar.gz cpython-4117e5428bf1ff3d26d23bd77472265412473ad9.tar.bz2 |
nannified
Diffstat (limited to 'Demo/zlib')
-rwxr-xr-x | Demo/zlib/minigzip.py | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/Demo/zlib/minigzip.py b/Demo/zlib/minigzip.py index 0bfe355..eefdc39 100755 --- a/Demo/zlib/minigzip.py +++ b/Demo/zlib/minigzip.py @@ -31,64 +31,64 @@ input=open(filename) ; output=open(outputname, 'w') if compressing: output.write('\037\213\010') # Write the header, ... - output.write(chr(FNAME)) # ... flag byte ... + output.write(chr(FNAME)) # ... flag byte ... - import os # ... modification time ... + import os # ... modification time ... statval=os.stat(filename) mtime=statval[8] write32(output, mtime) - output.write('\002') # ... slowest compression alg. ... - output.write('\377') # ... OS (=unknown) ... - output.write(filename+'\000') # ... original filename ... + output.write('\002') # ... slowest compression alg. ... + output.write('\377') # ... OS (=unknown) ... + output.write(filename+'\000') # ... original filename ... crcval=zlib.crc32("") compobj=zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS, - zlib.DEF_MEM_LEVEL, 0) + zlib.DEF_MEM_LEVEL, 0) while (1): - data=input.read(1024) - if data=="": break - crcval=zlib.crc32(data, crcval) - output.write(compobj.compress(data)) + data=input.read(1024) + if data=="": break + crcval=zlib.crc32(data, crcval) + output.write(compobj.compress(data)) output.write(compobj.flush()) - write32(output, crcval) # ... the CRC ... - write32(output, statval[6]) # and the file size. + write32(output, crcval) # ... the CRC ... + write32(output, statval[6]) # and the file size. else: magic=input.read(2) if magic!='\037\213': - print 'Not a gzipped file' ; sys.exit(0) + print 'Not a gzipped file' ; sys.exit(0) if ord(input.read(1))!=8: - print 'Unknown compression method' ; sys.exit(0) + print 'Unknown compression method' ; sys.exit(0) flag=ord(input.read(1)) - input.read(4+1+1) # Discard modification time, - # extra flags, and OS byte. + input.read(4+1+1) # Discard modification time, + # extra flags, and OS byte. if flag & FEXTRA: - # Read & discard the extra field, if present - xlen=ord(input.read(1)) - xlen=xlen+256*ord(input.read(1)) - input.read(xlen) + # Read & discard the extra field, if present + xlen=ord(input.read(1)) + xlen=xlen+256*ord(input.read(1)) + input.read(xlen) if flag & FNAME: - # Read and discard a null-terminated string containing the filename - while (1): - s=input.read(1) - if s=='\000': break + # Read and discard a null-terminated string containing the filename + while (1): + s=input.read(1) + if s=='\000': break if flag & FCOMMENT: - # Read and discard a null-terminated string containing a comment - while (1): - s=input.read(1) - if s=='\000': break + # Read and discard a null-terminated string containing a comment + while (1): + s=input.read(1) + if s=='\000': break if flag & FHCRC: - input.read(2) # Read & discard the 16-bit header CRC + input.read(2) # Read & discard the 16-bit header CRC decompobj=zlib.decompressobj(-zlib.MAX_WBITS) crcval=zlib.crc32("") length=0 while (1): - data=input.read(1024) - if data=="": break - decompdata=decompobj.decompress(data) - print len(decompdata) - output.write(decompdata) ; length=length+len(decompdata) - crcval=zlib.crc32(decompdata, crcval) + data=input.read(1024) + if data=="": break + decompdata=decompobj.decompress(data) + print len(decompdata) + output.write(decompdata) ; length=length+len(decompdata) + crcval=zlib.crc32(decompdata, crcval) decompdata=decompobj.flush() output.write(decompdata) ; length=length+len(decompdata) crcval=zlib.crc32(decompdata, crcval) |