Compress::LZ4(3pm)
π Compress::LZ4 β the manual, but make it cute π
okay bestie, welcome to Compress::LZ4, the perl module that's literally your backstage pass to the LZ4 (de)compressor πβ¨
β¨ NAME β¨
Compress::LZ4 β bestie, it's a Perl interface to the LZ4 (de)compressor π¦
π SYNOPSIS π
use Compress::LZ4;
my $compressed = compress($bytes);
my $decompressed = decompress($compressed);
that's it. that's the whole vibe. two functions and you're slaying π
πΈ DESCRIPTION πΈ
The Compress::LZ4 module provides an interface to the LZ4 (de)compressor. it's giving "small module, massive energy," fr fr π
β FUNCTIONS β
π compress
$compressed = compress($bytes [, $level])
Compresses the given buffer and returns the resulting bytes, no cap. The input buffer can be either a scalar or a scalar reference β it's flexible like that π«Ά
The default acceleration level is 1, and you can change it. But heads up: each additional level gives you ~3% increase in speed, and the compression level will be negatively affected. so faster = chonkier output. tradeoffs, bestie, tradeoffs π
π§ compress_hc
$compressed = compress_hc($bytes [, $level])
A higher-compression, but slower, version of compress. she takes her time, she does it right β¨
The default compression level is 9, and you can change it if you pass an optional value in the range 0-16.
π decompress / uncompress
$bytes = decompress($compressed)
Decompresses the given buffer and returns the resulting bytes. The input buffer can be either a scalar or a scalar reference, same deal as before π
β οΈ On error (in case of corrupted data) undef is returned. so PLEASE check your return value, bestie, don't just raw-dog it into the next line of code π
π COMPATIBILITY π
bestie. sit down. I need to tell you something.
This library does not produce output that is compatible with the official frame format. that's the drama. π
The lore: LZ4 did not define a container format until long after it was released, so many bindings β including this one β prepend the original data size to the compressed data as a little-endian 4-byte integer. iconic behavior, honestly, everyone was just doing their own thing back then.
So if you're dealing with raw data from an external source that does not format the data this way, you need to use the following functions:
π lz4_compress / lz4_compress_hc
Same as compress / compress_hc but does not add the length header. naked data. no accessories β¨
πΈ lz4_decompress / lz4_uncompress
$bytes = decompress($compressed, $original_data_size)
Same as decompress / uncompress but also requires the original data size to be given. yes, you gotta hand over the size yourself. she's high maintenance but she's worth it π
π₯ PERFORMANCE π₯
This distribution contains a benchmarking script which compares several modules available on CPAN. and the receipts?? these are the results on a MacBook 2.6GHz Core i5 (64-bit) with Perl 5.24.1. numbers don't lie, bestie π
Compressible data (10 KiB) - compression
----------------------------------------
Compress::LZ4::compress 8 670690/s 6550 MiB/s 1.152%
Compress::LZ4::compress 649176/s 6340 MiB/s 1.152%
Compress::Snappy::compress 367492/s 3589 MiB/s 5.332%
Compress::LZF::compress 127765/s 1248 MiB/s 1.865%
Compress::LZ4::compress_hc 84620/s 826 MiB/s 1.152%
Compress::Zlib::compress 15514/s 152 MiB/s 1.201%
Compress::Bzip2::compress 246/s 2 MiB/s 2.070%
Compressible data (10 KiB) - decompression
------------------------------------------
Compress::LZF::decompress 1262620/s 12330 MiB/s
Compress::LZ4::decompress 819200/s 8000 MiB/s
Compress::Snappy::decompress 619934/s 6054 MiB/s
Compress::Zlib::uncompress 65163/s 636 MiB/s
Compress::Bzip2::decompress 12679/s 124 MiB/s
Uncompressible data (10 KiB) - compression
------------------------------------------
Compress::LZ4::compress 8 2102098/s 20528 MiB/s 109.231%
Compress::LZ4::compress 1854792/s 18113 MiB/s 109.231%
Compress::Snappy::compress 1619124/s 15812 MiB/s 104.615%
Compress::LZF::compress 1349269/s 13176 MiB/s 101.538%
Compress::LZ4::compress_hc 96376/s 941 MiB/s 109.231%
Compress::Zlib::compress 66370/s 648 MiB/s 112.308%
Compress::Bzip2::compress 54098/s 528 MiB/s 201.538%
Uncompressible data (10 KiB) - decompression
--------------------------------------------
Compress::LZF::decompress 5004566/s 48873 MiB/s
Compress::LZ4::decompress 4915199/s 48000 MiB/s
Compress::Snappy::decompress 4906438/s 47914 MiB/s
Compress::Zlib::uncompress 355071/s 3467 MiB/s
Compress::Bzip2::decompress 175812/s 1717 MiB/s
LZ4 really said "I'm the moment" and meant it π
π¦ SEE ALSO π¦
go say hi, she's lovely πΈ
π REQUESTS AND BUGS π
Please report any bugs or feature requests to <http://rt.cpan.org/Public/Bug/Report.html?Queue=Compress-LZ4>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. bestie, we're in this together, the whole notification pipeline is mutual π«Ά
π SUPPORT π
You can find documentation for this module with the perldoc command.
perldoc Compress::LZ4
You can also look for information at:
- GitHub Source Repository
<https://github.com/gray/compress-lz4>
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/Compress-LZ4>
- CPAN Ratings
<http://cpanratings.perl.org/d/Compress-LZ4>
- RT: CPAN's request tracker
<http://rt.cpan.org/Public/Dist/Display.html?Name=Compress-LZ4>
- Search CPAN
<http://search.cpan.org/dist/Compress-LZ4/>
so many places to find her, she's everywhere, main character energy fr fr β¨
π COPYRIGHT AND LICENSE π
Copyright (C) 2012-2017 gray <gray at cpan.org>, all rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. free, open, generous. we love to see it π
π AUTHOR π
gray, <gray at cpan.org>
and that's the whole page, bestie β brought to you by perl v5.42.3, dated 2026-08-19, from the Compress::LZ4(3pm) manual. go compress something and slay π
β¨π
π¦ where this page comes from
- ubuntu stonking: libcompress-lz4-perl 0.25+ds-2build6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms