File::Raw · File::Raw::Gzip 0.03

File::Raw::Gzip

Gzip, zlib and raw deflate, on the way in and out.

Compressed files read and written as if they were not: plugin => 'gzip' inflates on read and deflates on write. It streams line by line, and it is the plugin to put first in a chain, so a .csv.gz is rows in one call.

Registers gzip

use File::Raw ();
use File::Raw::Gzip;

my $bytes = File::Raw::slurp('access.log.gz', plugin => 'gzip');

File::Raw::spew('copy.log.gz', $bytes, plugin => 'gzip', level => 9);

# Streamed: the file is inflated as it is read, never whole.
File::Raw::each_line('access.log.gz', sub {
    print "$_\n" if / 500 /;
}, plugin => 'gzip');

What you get

  • Three formats

    gzip (RFC 1952) by default, zlib (RFC 1950) with mode => 'zlib', and raw deflate (RFC 1951) with mode => 'raw'.

  • Read, write, stream

    slurp inflates, spew deflates at level 0 to 9, and each_line inflates as it reads, never the whole file in memory.

  • First in a chain

    A pure byte transform, so it composes: plugin => ['gzip', 'csv'] reads a .csv.gz to rows and writes rows back to one.

The numbers

Against the fastest alternative that was installed, and shown whichever way it went.

  • 6.8x read a gzipped 7.5 MB log, against IO::Uncompress::Gunzip File::Raw::Gzip 0.03 at 313/s, IO::Uncompress::Gunzip 2.213 at 45.9/s
  • 1.7x write a 7.5 MB log gzipped, level 6, against IO::Compress::Gzip File::Raw::Gzip 0.03 at 25.6/s, IO::Compress::Gzip 2.213 at 15.2/s
  • 5.1x read a gzipped CSV file into rows, against Gunzip + Text::CSV_XS File::Raw::Gzip 0.03 at 27.3/s, Gunzip + Text::CSV_XS 2.213 at 5.4/s

Measured on Apple M5, darwin with perl 5.42.0, 2026-10-19: each entry timed for 3 CPU seconds by the Benchmark module, 3 times, the median kept, after checking that both sides produced the same result. Every number.

Works with

Chains from its documentation: the plugins run left to right on a read, right to left on a write.

Get it

cpanm File::Raw::Gzip

The reference

Every File::Raw dist