LZF(3)
LZF(3) π
okay bestie, you're looking at LZF(3) from User Contributed Perl Documentation, and the manual name is Compress::LZF β say it with me: extremely light-weight Lempel-Ziv-Free compression. The vibes are fast, tiny, and free. π¦
β¨ NAME β¨
Compress::LZF β extremely light-weight Lempel-Ziv-Free compression. That's the whole NAME moment, and it ate. π
π¦ SYNOPSIS π¦
Here's the code, exactly as it appears, because we do not mess with code in this house:
# import compress/decompress functions
use Compress::LZF;
# the same as above
use Compress::LZF ':compress';
$compressed = compress $uncompressed_data;
$original_data = decompress $compressed;
# import sfreeze, sfreeze_cref and sfreeze_c
use Compress::LZF ':freeze';
$serialized = sfreeze_c [4,5,6];
$original_data = sthaw $serialized;
πΈ DESCRIPTION πΈ
LZF is an extremely fast compression algorithm β not that much slower than a pure memcpy, fr fr. It's ideal for applications where you want to save some space but not at the cost of speed. It is ideal for repetitive data as well. The module is self-contained and very small (no large library to be pulled in), so it's giving tiny-iconic. It is also free, so there should be no problems incorporating this module into commercial programs. π«Ά
The page literally says: βI have no idea wether any patents in any countries apply to this algorithm, but at the moment it is believed that it is free from any patents.β So that's the patent tea: unknown, but currently believed free. π
π₯ FUNCTIONS π₯
These are the functions, with all their little details kept intact. No cap.
$compressed = compress $uncompressedβ Try to compress the given string as quickly and as much as possible. In the worst case, the string can enlarge by 1 byte, but that should be the absolute exception. You can expect a 45% compression ratio on large, binary strings. π₯$decompressed = decompress $compressedβ Uncompress the string (compressed bycompress) and return the original data. Decompression errors can result in either broken data (there is no checksum kept) or a runtime error. So yes, bestie: no checksum, and broken data is literally possible. π$serialized = sfreeze $value (simplified freeze)β Often there is the need to serialize data into a string. This function does that by using theStorablemodule. It does the following transforms:
undef (the perl undefined value)
=> a special cookie (undef'ness is being preserved)
IV, NV, PV (i.e. a _plain_ perl scalar):
=> stays as is when it contains normal text/numbers
=> gets serialized into a string
RV, undef, other funny objects (magical ones for example):
=> data structure is freeze'd into a string.
That is, it tries to leave βnormalβ, human-readable data untouched but still serializes complex data structures into strings. The idea is to keep readability as high as possible, and in cases readability can't be helped anyways, it tries to compress the string. β¨
The sfreeze functions will enlarge the original data one byte at most and will only load the Storable method when neccessary. π
$serialized = sfreeze_c $value (sfreeze and compress)β Similar tosfreeze, but always tries to βcβompress the resulting string. This still leaves most small objects (most numbers) untouched. Thesfreeze_cfunction uses a different algorithm that is slower but usually achieves better compression. π$serialized = sfreeze_cr $value (sfreeze and compress references)β Similar tosfreeze, but tries to βcβompress the resulting string unless it's a βsimpleβ string. References for example are not βsimpleβ and as such are being compressed. π¦$original_data = sthaw $serializedβ Recreate the original object from it's serialized representation. This function automatically detects all the different sfreeze formats. π«ΆCompress::LZF::set_serializer $package, $freeze, $thawβ Set the serialize module and functions to use. The default isStorable,Storable::net_mstoreandStorable::mretrieve, which should be fine for most purposes. π
π SUPPORT FOR THE PERL MULTICORE SPECIFICATION π
This module supports the perl multicore specification (http://perlmulticore.schmorp.de/) for all compression (> 2000 octets) and decompression (> 4000 octets) functions. Numbers stay exactly like that, bestie: > 2000 octets for compression, > 4000 octets for decompression. β
π NO SUPPORT FOR BEST METHODS π
compress_best and other _best subroutines were removed because liblzf-3.6 does not yet support them. See https://bugzilla.redhat.com/show_bug.cgi?id=1268333. So if you were looking for the best methods: not here, bestie. π«Ά
π¦ SEE ALSO π¦
- Other
Compress::*modules, especiallyCompress::LZV1(an older, less speedy module that guarentees only 1 byte overhead worst case) andCompress::Zlib. http://liblzf.plan9.de/π
π AUTHOR π
This perl extension and the underlying liblzf were written by Marc Lehmann <schmorp@schmorp.de> (See also http://liblzf.plan9.de/). Iconic author behavior, honestly. π
π BUGS π
The original page's BUGS section has no bug notes listed β it's just the heading. So there's nothing to report here, bestie. π«Ά
stay compressed, stay iconic β this was perl v5.32.1, dated 2019-10-17, and the page is LZF(3). π
β¨
π¦ where this page comes from
- epel 9: perl-Compress-LZF 3.8-14.el9 Β· GPL+ or Artistic
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms