Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    gzip file problem

    Scheduled Pinned Locked Moved MicroPython
    4 Posts 2 Posters 17 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kjm
      last edited by

      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 formats

      with 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 bytes
      

      What 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?

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @kjm
        last edited by livius

        @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.

        think about people first, then computers

        1 Reply Last reply Reply Quote 1
        • K Offline
          kjm
          last edited by kjm

          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 bytes
          

          only 1 print

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @kjm
            last edited by

            @kjm said in gzip file problem:

            if '\x1f\x08'

            what if you write

            if b'\x1f\x08' in
            

            think about people first, then computers

            1 Reply Last reply Reply Quote 0

            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
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom