Skip to content
forked from ning/compress

Basic LZF codec, compatible with standard C LZF package

License

Notifications You must be signed in to change notification settings

abramsm/compress

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ning-Compress

Overview

Ning-compress is a Java library for encoding and decoding data in LZF format, written by Tatu Saloranta ([email protected])

Data format and algorithm based on original LZF library by Marc A Lehmann

Format differs slightly from some other adaptations, such as one used by H2 database project (by Thomas Mueller); although internal block compression structure is the same, block identifiers differ. This package uses the original LZF identifiers to be 100% compatible with existing command-line lzf tool(s).

LZF alfgorithm itself is optimized for speed, with somewhat more modest compression: compared to Deflate (algorithm gzip uses) LZF can be 5-6 times as fast to compress, and twice as fast to decompress.

API usage

Both compression and decompression can be done either block-by-block or using Java stream.

When reading compressed data from a file you can do it simply creating a LZFInputStream and use it for reading content

InputStream in = new LZFInputStream(new FileInputStream("data.lzf"));

(note, too, that stream is buffered: there is no need to or benefit from using BufferedInputStream!)

and similarly you can compress content using LZFOutputStream:

OutputStream out = new LZFOutputStream(new FileOutputStream("results.lzf"));

Compressing and decompressing individual blocks is as simple:

byte[] compressed = LZFEncoder.encode(uncompressedData);
byte[] uncompressed = LZFDecoder.decode(compressedData);

Finally, note that LZF encoded chunks have length of at most 64 kB; longer content will be split into such chunks.

Use as command-line tool

Note that resulting jar is both an OSGi bundle, and a command-line tool (has manifest that points to 'com.ning.compress.lzf.LZF' as the class having main() method to call).

This means that you can use it like:

java -jar compress-lzf-0.8.4.jar

(which will display necessary usage arguments)

Related

Check out jvm-compress-benchmark for comparison of space- and time-efficiency of this LZF implementation, relative other available Java-accessible compression libraries.

More

Check out Project Wiki for more information.

About

Basic LZF codec, compatible with standard C LZF package

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.8%
  • Shell 0.2%