Raku Land

LZW::Revolunet

cpan:KNARKHOV

Lempel–Ziv–Welch (LZW) algorithm implementation in Perl 6

Synopsis

my $data = 'Тексты - это не энциклопедические и не лингвистические системы.' x 255;

# create LWZ object
my $lzw = LZW::Revolunet.new;

# set dictionary size, by default 57344
$lzw.set_dictsize( 97000 );

# compress
my $cmp  = $lzw.compress( $lzw.encode_utf8($data) );

# decompress
my $dcmp = $lzw.decode_utf8( $lzw.decompress($cmp) );

# validate
if ( !($dcmp eq $data) ) {
    die "decompressed data is corrupted";
}

# compress/decompress statistics
('compression ratio ' ~ floor($cmp.chars/$dcmp.chars*100) ~ '%').say;

Description

LZW::Revolunet — Perl6 implementation of universal lossless data compression algorithm created by Abraham Lempel, Jacob Ziv, and Terry Welch. This module is based on JavaScript implementation (lzw_encoder.js) by Julien Bouquillon

License

LZW::Revolunet is free and opensource software, so you can redistribute it and/or modify it under the terms of the The Artistic License 2.0.

Author

Please contact me via LinkedIn or Twitter. Your feedback is welcome at narkhov.pro.

See also

LZW Data Compression