Hi,
I was wondering if anyone might be able to shed some light on an issue I am having. I am trying to expand a zip file on a raspberry pi pico with micropython and not having much success. I am using the uzlib module, which after some googling seems to be the way to go. However, the code is failing with a -3 error which I believe is something to do with not being able to understand the format of the zip file.
Traceback (most recent call last):
File "<stdin>", line 20, in <module>
File "<stdin>", line 10, in unzip
ValueError: -3
The test zip I am using is very simple and was created from the command line using:
touch text.txt
zip test.zip text.txt
It also doesn’t work with the third party zip I also ultimately want to use.
The code to unzip the file is as follows:
import uzlib
import os
def unzip(zip_file_path, extract_path):
with open(zip_file_path, "rb") as zip_file:
zip_data = zip_file.read()
# Decompress the zip data.
try:
files = uzlib.decompress(zip_data)
except:
print("Decompress failed!")
# Extract the files to the specified extract path.
try:
for filename, data in files.items():
with open(os.path.join(extract_path, filename), "wb") as output_file:
output_file.write(data)
except:
print("Write failed!")
zip_file_path = "test.zip"
extract_path = "/tmp"
unzip(zip_file_path, extract_path)
Any ideas or better ways to unzip a file would be gratefully received.
I should probably also say that the files are all in the root dir of the pico.