Skip to main content

CFFI-based Python binding for LZF stream compression

Project description

https://travis-ci.org/lordmauve/lzf.svg?branch=master

lzf allows reading and writing files compressed with the LZF compression format.

To crib some of the features listed for LibLZF:

  • Very fast compression speeds.

  • Mediocre compression ratios - you can usually expect about 40-50% compression for typical binary data Easy to use (just two functions, no state attached).

  • Freely usable (BSD-type-license)

API

This package provides reading and writing LZF data as Python file like objects.

lzf.open(file, mode='r', encoding=None, errors=None)

Open a LZF stream for reading or writing.

file may be a path to an on-disk file, or a file-like object open for reading or writing (whatever you pass to mode).

mode must be r or w to indicate reading or writing, optionally with b or t to indicate binary or text-mode IO. If the mode is text (the default), then U is also accepted to turn on universal newline mode.

encoding and errors are as for the built-in open() function.

Note that lzf.open() takes the Python 3 model for text IO, even on Python 2. Unless mode contains 'b', then the returned file-like object will read or write Unicode strings.

Examples

To open an on-disk LZF-compressed text file and print it linewise:

import lzf

with lzf.open('/path/to/file.txt.lzf') as f:
    for line in f:
        print(line)

To compress some binary data with LZF:

import lzf

with lzf.open('/path/to/file.lzf', 'wb') as f:
    f.write(b'hello world')

To read LZF compressed CBOR structures from a URL:

import lzf
import cbor2
from urllib.request import urlopen  # Use urllib2 in Python 2

SOME_URL = 'http://example.com/data.cbor.lzf'

with lzf.open(urlopen(SOME_URL), 'rb') as f:
    print(cbor2.load(f))

(You’ll need cbor2 installed if you want to try this.)

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

lzf-0.1.tar.gz (28.4 kB view details)

Uploaded Source

File details

Details for the file lzf-0.1.tar.gz.

File metadata

  • Download URL: lzf-0.1.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lzf-0.1.tar.gz
Algorithm Hash digest
SHA256 2163a5172f7328baa4a5a0a351617a4d92a5d264975e67f581ed24a9dcf8893b
MD5 b9094aa8ea99ab95644dc82525ffb5e8
BLAKE2b-256 eff770aa6aacd6bc865e74dae319bb262078d59f6cf90584da2bbe7307b52565

See more details on using hashes here.

Supported by

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