Rand Stats




This is a (hopefully) nice interface to zlib. It compresses and uncompresses data using zlib native library.


use Compress::Zlib;

my $wrapped = Compress::Zlib::Wrap.new($handle); # can be a socket, filehandle, etc
my $wrapped = zwrap($handle); # does the same thing as the above line

my $response = $wrapped.get;

gzslurp("file.gz"); # reads in a gzipped file
gzspurt("file.gz", "stuff"); # spits out a gzipped file
use Compress::Zlib;

my $compressor = Compress::Zlib::Stream.new;
loop {

my $decompressor = Compress::Zlib::Stream.new;
while !$decompressor.finished {
    my $data-chunk = $decompressor.inflate($socket.read($size));
use Compress::Zlib;

my $compressed = compress($string.encode('utf8'));
my $original = uncompress($compressed).decode('utf8');

Handle Wrapper

Returns a wrapped handle that will read and write data in the compressed format. For example:

use Compress::Zlib;

my $file   = "data.txt.gz";
my $handle = try open $file or die "Error reading $file: $!";
my $zwrap  = zwrap($handle, :gzip);

for $zwrap.lines {


CATCH { default { die "Error reading $file: $_" } }


Stream Class

This currently has very few options. Over time, I will add support for custom compression levels, gzip/raw deflate streams, etc. If you need a specific feature, open an issue and I will move it to the top of my priority list.

Misc Functions

NOTE: These only handle zlib format data, not gzip or deflate.