Skip to main content

LZ4Frame Bindings and tools for Python

Project description

https://travis-ci.org/darkdragn/lz4file.svg?branch=master

Overview

This package consists of two parts:

  1. lz4f - bindings for all lz4frame functions

  2. lz4tools - a zipfile-like file wrapper class and tarfile-like class for lz4 compressed files.

Usage

I would recommend against using lz4f directly except in debug/testing situations. If necessary, a compress or decompress operation first needs a context that will be used with all lz4f functions:

lz4f compression the hard way:
>>> import lz4f
>>> inputFile = open('fileIn')
>>> cCtx = lz4f.createCompressionContext
>>> header = lz4f.compressBegin(cCtx)
>>> data = lz4f.compressUpdate(inputFile.read(), cCtx)
>>> end = lz4f.compressEnd(cCtx)
>>> with open('output.lz4', 'w') as out:
...     out.write(header)
...     out.write(data)
...     out.write(end)
...     out.flush()
...     out.close()
lz4f compression the easy way:
>>> import lz4f
>>> with open('output.lz4') as out:
...     with open('fileIn') as inFile:
...         out.write(lz4f.compressFrame(inFile.read())
...     out.flush()
...     out.close()

Advantages and disadvntages: The easy way takes more ram. It reads the contents of the file into a buffer, passes it and compresses it all in one go. With the hard way you can have it read as little or as much as you like. For instance, you can break up the input into 64k chunks. Each chunk could be read, compressed and dropped to disk to conserve ram.

The lz4file class is currently read only. Right now it is a bit rough around the edges, however over the next couple of weeks, I will finish adding some document strings, and such to make it more user friendly. As soon as I get a chance I will make it write capable. The easiest way to use it is with either the open or openTar methods. That’s right! There is a lz4Tar class in the module that is a subclass of tarfile.

lz4tools tar example:
>>> import lz4tools
>>> lz4tools.compressTarDefault('src')
>>> testTar = lz4tools.openTar('src.tar.lz4')
>>> testTar.list()
-rwxr-xr-x darkdragn/darkdragn          0 2014-10-02 23:06:09 src/
-rw-r--r-- darkdragn/darkdragn      29905 2014-09-16 18:29:45 src/lz4hc.c
-rw-r--r-- darkdragn/darkdragn       6781 2014-09-16 18:29:45 src/xxhash.h
-rw-r--r-- darkdragn/darkdragn      25662 2014-09-16 18:29:45 src/xxhash.c
-rw-rw-r-- darkdragn/darkdragn      13894 2014-10-02 20:22:09 src/lz4frame.h
-rw-rw-r-- darkdragn/darkdragn      46241 2014-10-02 20:22:09 src/lz4.c
-rw-r--r-- darkdragn/darkdragn       8832 2014-09-16 18:29:45 src/lz4hc.h
-rw-rw-r-- darkdragn/darkdragn      11734 2014-10-02 23:06:08 src/python-lz4f.c
-rw-rw-r-- darkdragn/darkdragn       2554 2014-10-02 20:22:09 src/python-lz4f.h
-rw-r--r-- darkdragn/darkdragn      14882 2014-09-18 01:28:06 src/lz4.h
-rw-rw-r-- darkdragn/darkdragn      50141 2014-10-02 23:04:05 src/lz4frame.c
lz4tools file example:
>>> import lz4tools
>>> lz4tools.compressFileDefault('setup.py')
>>> testFile = lz4tools.open('setup.py.lz4')
>>> testFile.blkDict
{0: {'decomp_e': 1445, 'compressed_begin': 7, 'blkSize': 923}}
>>> testFile.seek(1002)
>>> print testFile.read()
    test_suite = "nose.collector",
    keywords = ['lz4', 'lz4frame', 'lz4file', 'lz4tar'],
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'License :: OSI Approved :: BSD License',
        'Intended Audience :: Developers',
        'Programming Language :: C',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
    ],
)

And thus ends the brief tutoral.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lz4tools-1.2.1.tar.gz (53.1 kB view details)

Uploaded Source

File details

Details for the file lz4tools-1.2.1.tar.gz.

File metadata

  • Download URL: lz4tools-1.2.1.tar.gz
  • Upload date:
  • Size: 53.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lz4tools-1.2.1.tar.gz
Algorithm Hash digest
SHA256 266bcd4c63f55854e53be7ce9a5749fd2b89f5bcbdb01303e8fddf9f180673fd
MD5 778c4d0b1567f3bea47709731400e07a
BLAKE2b-256 5ebd15d2fa842b88993989eed34c9924c8ffb155339163bb66d97662b6d37e0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page