-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1c8d4b6
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__/ | ||
*.py[cod] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Bill Sideris | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# jz | ||
A zlib based file compression utility for circuitpython | ||
<br /><br /> | ||
|
||
## 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import zlib | ||
from gc import collect | ||
from sys import argv | ||
from os import getcwd, chdir | ||
|
||
VERSION = "0.0.1" | ||
|
||
def compress(*argv): | ||
""" | ||
Note: compression cannot be done on the controller | ||
itself at the moment. | ||
Example: | ||
>>> import jz | ||
>>> jz.compress("file1", "file2", "target_filename") | ||
""" | ||
|
||
#starting print | ||
objc = len(argv)-1 | ||
targetfile = argv[objc] | ||
print(f"Compressing {str(objc)} files onto {targetfile}") | ||
|
||
#let's create the control string | ||
ctlstr = "" | ||
# the control string format is: | ||
# file1 file1len file2 file2len |eocf | ||
for i in range(0, objc): | ||
ctlstr += i | ||
with open(i, "rb") as togetlelen: | ||
inpt = togetlelen.read() | ||
togetlelen.close() | ||
del togetlelen | ||
del i | ||
collect() | ||
collect() | ||
|
||
|
||
#cleanup | ||
del objc | ||
del targetfile | ||
|
||
def decompress(filee, directory="."): | ||
""" | ||
Example: | ||
>>> import jz | ||
>>> jz.decompress("jzfile", directory="path") | ||
The file will be decompressed onto "directory". "." if not specified | ||
""" | ||
olddir = getcwd() | ||
chdir(directory) | ||
|
||
chdir(olddir) | ||
del olddir | ||
collect() | ||
|
||
def help(): | ||
print(f""" | ||
About: jz file compression module. | ||
Version: {VERSION} - Author: Bill Sideris (bill88t) | ||
This project is licenced under the MIT licence. | ||
Usage: jz.compress(\"file1\", \"file2\", \"jz_archive_name\") | ||
jz.decompress(\"jz_archive_name\") | ||
""") |