Package: pybcl
pybclAlgorithmsRequirementsInstallationUsageHeader variantOriginal libraryThis project brings the basic compression library (BCL) to Python.
These are not bindings, the wrapped library is bundled in the compiled binary.
Afew changeshave been made to the original BCL in order to (hopefully) prevent segmentation
faults for LZ77 and RLE decompression, and to ease the development of the module.AlgorithmsThe BCL contains a C implementation of these five algorithms:HuffmanLempel-Ziv (LZ77)RiceRLE (Run-length encoding)Shannon-FanoRequirementsPython 3.7+Installationpip install pybclUsage[!CAUTION]
While there's been an effort to prevent buffer overflows for the RLE and LZ77
decompression algorithms, the other three are very likely to segfault if you
give them corrupt/random data.APIfrompybclimportcompress,decompress,...# Functions exposed by the C extension.defcompress(data,algo,header=False):...defdecompress(data,algo=0,outsize=0):...# Shortcut functions.defhuffman_compress(data,header=False):...deflz_compress_fast(data,header=False):...defrice_compress(data,format,header=False):...defrle_compress(data,header=False):...defsf_compress(data,header=False):...defhuffman_decompress(data,outsize=0):...deflz_decompress(data,outsize=0):...defrice_decompress(data,format,outsize=0):...defrle_decompress(data,outsize=0):...defsf_decompress(data,outsize=0):...For compression you can choose whether the header should be included in the result.For decompression you can overrideoutsizeby giving a positive value.algoandoutsizearen't required if the data contains a header.Two enums are provided for the algorithms and Rice formats. Example:frompybclimportAlgorithm,RiceFormatdata=b"test"compressed=compress(data,Algorithm.RICE8)decompressed=rice_decompress(compressed,RiceFormat.UINT8,len(data))Command lineCompression:usage: pybcl c [-h] [-a ALGO] [-o OFFSET] [-m SIZE] [-f] [--no-header] src dest

positional arguments:
  src                         input file
  dest                        output file

options:
  -h, --help                  show this help message and exit
  -a ALGO, --algo ALGO        algorithm for (de)compression. Not required for decompression if a header is present
  -o OFFSET, --offset OFFSET  position in src where to start reading from
  -m SIZE, --maxread SIZE     max amount of bytes to read from src. Default: all that can be read
  -f, --force                 overwrite dest
  --no-header                 do not write a header for the fileDecompression:usage: pybcl d [-h] [-a ALGO] [-o OFFSET] [-m SIZE] [-f] [-s SIZE] [--hvariant] src dest

positional arguments:
  src                         input file
  dest                        output file

options:
  -h, --help                  show this help message and exit
  -a ALGO, --algo ALGO        algorithm for (de)compression. Not required for decompression if a header is present
  -o OFFSET, --offset OFFSET  position in src where to start reading from
  -m SIZE, --maxread SIZE     max amount of bytes to read from src. Default: all that can be read
  -f, --force                 overwrite dest
  -s SIZE, --outsize SIZE     required if no header
  --hvariant                  force reading the header variantWhen decompressing data that has a header with LZ77 or RLE, if you get anOutputOverrunerror you can override the header's outsize to specify a higher value.Header variantSome camera firmwares contain parts that are compressed with a modified version
of the BCL that adds the size of the compressed data to the header and replaces
two of the always empty bytes of the algo by unknown data (maybe a checksum).
AHeaderVariantclass is provided for this specific case. For now only the CLI
makes use of this class. Note that this has nothing to do with the original
library and is only included because I need it for another project.
Seeherefor an example.Original libraryThe BCL is written byMarcus Geelnardand
licensed under the terms of the zlib license.You can find it here:https://web.archive.org/web/20181025055443/http://bcl.comli.eu/https://sourceforge.net/projects/bcl/https://github.com/mbitsnbites/bclhttps://gitlab.com/mbitsnbites/bclIt comes with the basic file compressor, or BFC, which is a test application for
the BCL. Data compressed with the BFC starts with theBCL1magic.