gzip file problem
-
I've got a small gzip compressed file called Lcomp.py
The file is valid & I can print it in both it's compressed & uncompressed formatswith open('Lcomp.py', 'r') as f: m=f.read(); print(); print('compressed L:'); s=repr(m); print(s); print(len(s), 'bytes') import uzlib; from uio import StringIO as s; u=uzlib.DecompIO(s(m),31); m=u.read(); print(); print('decomp: '); print(m); print(len(m), 'bytes') if '\x1f\x08' in m: import uzlib; from uio import StringIO as s; u=uzlib.DecompIO(s(m),31); m=u.read(); print(); print('if test decomp: '); print(m); print(len(m), 'bytes')gives
compressed L: '\x1f\x08\x08v<Ia\x04\x00L.py\x00]\r\n0\x10\uf17e\x03\x14\x0b*\x04?b\t\x1bx\x0c-\x05 4\U0001102e\x12S\x12\x07o"\x0b\x0b\x03\x001\x0cHy9\x08dg\x011+\x05d\x04\x18Vq\\$\x1b)\x07\x01]\x150(~\u64bc\u0379FkF7!kH,lrU\x0ee\x01a#2X\x03.\x0e\x06W\x10+\x0fmZ\x13\u02b1\x0e\x12\x1b\u05e0\x0f\x0132\x11!<%F\x08\x1c:\x05\x1685\x01K\x04zsU\x04\x03\x08~v\x13\x1b\x06\U0002f6ff\x1cn>\\I\x07\x00\x00\x00' 386 bytes decomp: b'[[72, 86, 148], [" if len(L)!=5: TxL.append([\'wrong list length\', len(L)); return\\r", " print(); print(\'new file:\'); print(nf); with open(\'newfile\', \'w\') as f: f.write(nf)\\r", " if \'[\' in m: TxL.append(m)\\r"], [72, 86, 148], [], []]\r\n' 247 bytesWhat I don't understand is why it fails to print a second time after I test it for the compression header '\x1f\x08' ? Any body see what I'm doing wrong?
-
@kjm
you have overridden value of m in second line
so in third line it is not the same operation as you decompress already decompressed value.And really better if you follow guaidance of writing python code, as you write all in one line.
Python designed indents to have more understandable code at first look. -
OK, I redid
def _decomp(c): import uzlib from uio import StringIO as s u=uzlib.DecompIO(s(c),31) n=u.read() print(); print('decomp: ') print(n) print(len(n), 'bytes') with open('Lcomp.py', 'r') as f: m=f.read() print(); print('compressed L:') s=repr(m); print(s) print(len(s), 'bytes') _decomp(m) if '\x1f\x08' in m: _decomp(m)but my problem persists
compressed L: '\x1f\x08\x08v<Ia\x04\x00L.py\x00]\r\n0\x10\uf17e\x03\x14\x0b*\x04?b\t\x1bx\x0c-\x05 4\U0001102e\x12S\x12\x07o"\x0b\x0b\x03\x001\x0cHy9\x08dg\x011+\x05d\x04\x18Vq\\$\x1b)\x07\x01]\x150(~\u64bc\u0379FkF7!kH,lrU\x0ee\x01a#2X\x03.\x0e\x06W\x10+\x0fmZ\x13\u02b1\x0e\x12\x1b\u05e0\x0f\x0132\x11!<%F\x08\x1c:\x05\x1685\x01K\x04zsU\x04\x03\x08~v\x13\x1b\x06\U0002f6ff\x1cn>\\I\x07\x00\x00\x00' 386 bytes decomp: b'[[72, 86, 148], [" if len(L)!=5: TxL.append([\'wrong list length\', len(L)); return\\r", " print(); print(\'new file:\'); print(nf); with open(\'newfile\', \'w\') as f: f.write(nf)\\r", " if \'[\' in m: TxL.append(m)\\r"], [72, 86, 148], [], []]\r\n' 247 bytesonly 1 print
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login