Skip to content

Commit

Permalink
jz_board addition
Browse files Browse the repository at this point in the history
  • Loading branch information
bill88t committed Jun 30, 2022
1 parent 831abc6 commit 73cd62c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ A zlib based file compression utility for circuitpython

## Important note

This utility will not be able to compress files on boards, you will have to use it on a host computer to compress files with.
This utility will not be able to compress files on boards, you will have to use it on a host computer to compress files with.<br />
<br />
For extracting file on a board, you are recommended to use the "_board" mpy versions, however the full one should work just fine.
Binary file added jz.mpy
Binary file not shown.
Binary file added jz_board.mpy
Binary file not shown.
53 changes: 53 additions & 0 deletions jz_board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from zlib import decompress
from gc import collect
from sys import exit
from os import getcwd, chdir

VERSION = "1.0-board"

def decompress(filee, directory="."):
print(f"Decompressing {filee} into {directory if directory != '.' else 'the current directory'}")
with open(filee,"rb") as inpf:
dataa = inpf.read()
inpf.close()
del inpf
olddir = getcwd()
chdir(directory)
unz = decompress(dataa)
del dataa
collect()
collect()
ctlstr = str(unz[:unz.find(bytes("|eocf","utf-8"),0)],"utf-8")
ctlarr = ctlstr.split()
offset = unz.find(bytes("|eocf","utf-8"),0)+5

for i in range(0, int(len(ctlarr)), 2): # skipping over len
fname = ctlarr[i]
lco = int(ctlarr[i+1])
print(f"Extracting: {fname} ({str(lco)} bytes)")
try:
with open(fname,"wb") as fout:
fout.write(unz[offset:offset+lco])
fout.flush()
fout.close()
del fout
except OSError:
print("Error: Could not write file")
exit(1)
offset += lco
del lco, fname
collect()
collect()
del unz
chdir(olddir)
del olddir
exit(0)

def help():
print(f"""
About: jz file compression module, board edition.
Version: {VERSION} - Author: Bill Sideris (bill88t)
This project is licenced under the MIT licence.
Usage: jz.decompress(\"jz_archive_name\")
""")
exit(0)

0 comments on commit 73cd62c

Please sign in to comment.