Zip File Extractor
- SureshVakati
- Posts: 42
- Joined: Fri Feb 24, 2017 3:52 pm
Zip File Extractor
Hello,
Are there any libraries available to extract '.ZIP' or '.RAR' files in SD card?
Are there any libraries available to extract '.ZIP' or '.RAR' files in SD card?
Re: Zip File Extractor
That's a "no", but there is one for TAR files: https://github.com/micropython/micropyt ... r/utarfile
Re: Zip File Extractor
The decompressor for zipfile is available. So if you're up to parsing the zip file format, then you could write one in pure python.
I've got C code that was never merged that does pieces of it on MicroPython. Frozen files wound up being more useful.
I've got C code that was never merged that does pieces of it on MicroPython. Frozen files wound up being more useful.
- SureshVakati
- Posts: 42
- Joined: Fri Feb 24, 2017 3:52 pm
Re: Zip File Extractor
Hello Dave,
Are you talking about uzlib module or gzip module? Can I pass a file name as argument to uzlib.decompress(data)?
Are you talking about uzlib module or gzip module? Can I pass a file name as argument to uzlib.decompress(data)?
Re: Zip File Extractor
uzlib is what zip uses. No it doesn't take a filename. You'd need to parse the zip file format and extract the compressed data and feed that into zlib.decompress.
-
- Posts: 2
- Joined: Thu May 14, 2020 11:22 pm
Re: Zip File Extractor
Hello All, following up on this as I am trying to do the same (extract contents of a zip). Forgive my noobness but is this thread saying that you can somehow use uzlib to decompress a .zip file? I have a Digi Xbee 3 running micropython v.1.12. and have a .zip file with three files in it (certificates with the file extension .pem).
Went here but this is all C code?
https://github.com/pfalcon/uzlib
Tried using this in my project but it's evidently not complete/working.
https://pypi.org/project/micropython-cpython-uzlib/
Any suggestions?
Went here but this is all C code?
https://github.com/pfalcon/uzlib
Tried using this in my project but it's evidently not complete/working.
https://pypi.org/project/micropython-cpython-uzlib/
Any suggestions?
Re: Zip File Extractor
uzlib only knows about the compression format used to compress a file inside a zip file. It doesn't know how to read a zip file though.
So you need to write some code to parse the ZIP file headers and such and get to the compressed data for a file. Once you've got that compressed data you can use uzlib to decompress that data.
So you need to write some code to parse the ZIP file headers and such and get to the compressed data for a file. Once you've got that compressed data you can use uzlib to decompress that data.
-
- Posts: 2
- Joined: Thu May 14, 2020 11:22 pm
Re: Zip File Extractor
Thanks for the reply dhylands. That's a few steps ahead of where I'm actually stuck. Just getting the uzlib module to be recognized seems to be a problem. uzlib.py from https://pypi.org/project/micropython-cpython-uzlib/ only contains the below. The other problem is that "zlib" from the import statement isn't on my micropython implementation (https://github.com/digidotcom/xbee-micropython).
Code: Select all
import micropython
from zlib import *
class DecompIO:
def __init__(self, stream, dict_bits):
self.stream = stream
self.decomp = decompressobj(dict_bits)
self.pending = b""
def read(self, size):
while len(self.pending) < size:
inp = self.stream.read(256)
if not inp:
break
outp = self.decomp.decompress(inp)
self.pending += outp
outp = self.pending[:size]
self.pending = self.pending[size:]
return outp