FastLZ
Python wrapper for FastLZ_, a lightning-fast lossless compression library.
Example:
from fastlz5 import compress, decompress s = decompress(compress("hello there world", level=1)) assert(s == "hello there world")
Example:
import os
import sys
import argparse
try:
from fastlz5 import compress, decompress
except ModuleNotFoundError:
sys.stderr.write(
'fastlz lib not found, please install it with "python -m pip install fastlz5"')
sys.exit(1)
# Breaks an array into chunks of n length each.
def chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
def bytes_to_c_array(bytes, variable_name):
output_c_array = (
"#include <stdint.h>\n" +
f"extern const uint8_t {variable_name}[{len(bytes)}] = " + "{\n"
)
for byte_block in chunks(bytes, 64):
output_c_array += ' '
for byte in byte_block:
output_c_array += f'{byte},'
output_c_array += '\n'
output_c_array += "};\n"
return output_c_array
def main():
parser = argparse.ArgumentParser(description='Prepare data file for teensy by compressing it and outputting a c-array')
parser.add_argument('--input', help='Input file', required=True)
parser.add_argument('--output', help='Output file, otherwise stream to stdout', required=False)
parser.add_argument('--variable-name', help='Name for the variable of c_array', required=False)
parser.add_argument('--no-compress', help='Disable FastLZ compression to file', action='store_true')
args = parser.parse_args()
if not os.path.exists(args.input):
sys.stderr.write(f'File {args.input} does not exist.\n')
sys.exit(1)
with open(args.input, "rb") as fd:
file_input_bytes = fd.read()
if not args.no_compress:
file_input_bytes = compress(file_input_bytes, level=1)
var_name = args.variable_name or "data"
output_c_array = bytes_to_c_array(file_input_bytes, var_name)
if args.output:
with open(args.output, "wt") as fd:
fd.write(output_c_array)
else:
sys.stdout.write(f"{output_c_array}\n")
if __name__ == '__main__':
main()
Release files for fastlz5 0.0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastlz5-0.0.1.4.tar.gz | 9.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastlz5-0.0.1.4-cp39-cp39-win_amd64.whl | CPython 3.9 | CPython 3.9 | Windows x86-64 | Details |
Total release size: 20.6 kB
Release files / fastlz5-0.0.1.4.tar.gz
| Download URL | fastlz5-0.0.1.4.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d389d010cb729cfbfd3fe03e7d257ab8aa2c455a1c408a25858cf9c87c32d20
|
|
BLAKE2b-256 checksum How to use checksums |
cf5ed7b90452cc177ffaeedbee79242c003bb57c0d3dd86a3bc5bf18d56371c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.0
|
Release files / fastlz5-0.0.1.4-cp39-cp39-win_amd64.whl
| Download URL | fastlz5-0.0.1.4-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 10.7 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
03f2c6e56ee8497e85dd076df26ebbb79b7b869957b9d55d1b966669e708a7b9
|
|
BLAKE2b-256 checksum How to use checksums |
a7d5ea1d6cc18c194b89712b2e7b71b3f83fe7bfc9ea426675c531275efa0436
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.0
|