LZF(3)

πŸ“¦
version 3.8 Β· 4 versions
, in epel 9

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 by compress) 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 the Storable module. 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 to sfreeze, but always tries to β€œc”ompress the resulting string. This still leaves most small objects (most numbers) untouched. The sfreeze_c function uses a different algorithm that is slower but usually achieves better compression. πŸŽ€
  • $serialized = sfreeze_cr $value (sfreeze and compress references) β€” Similar to sfreeze, 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 is Storable, Storable::net_mstore and Storable::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, especially Compress::LZV1 (an older, less speedy module that guarentees only 1 byte overhead worst case) and Compress::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