1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | Compress::LZF - extremely leight-weight Lev-Zimpel-Free compression |
3 | Compress::LZF - extremely light-weight Lempel-Ziv-Free compression |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | # import compress/decompress functions |
7 | # import compress/decompress functions |
8 | use Compress::LZF; |
8 | use Compress::LZF; |
… | |
… | |
13 | $original_data = decompress $compressed; |
13 | $original_data = decompress $compressed; |
14 | |
14 | |
15 | # import sfreeze, sfreeze_cref and sfreeze_c |
15 | # import sfreeze, sfreeze_cref and sfreeze_c |
16 | use Compress::LZF ':freeze'; |
16 | use Compress::LZF ':freeze'; |
17 | |
17 | |
18 | $compressed = sfreeze_c [4,5,6]; |
18 | $serialized = sfreeze_c [4,5,6]; |
19 | $original_data = sthaw $compressed; |
19 | $original_data = sthaw $serialized; |
20 | |
20 | |
21 | =head1 DESCRIPTION |
21 | =head1 DESCRIPTION |
22 | |
22 | |
23 | LZF is an extremely fast (not that much slower than a pure memcpy) |
23 | LZF is an extremely fast (not that much slower than a pure memcpy) |
24 | compression algorithm. It is ideal for applications where you want to save |
24 | compression algorithm. It is ideal for applications where you want to save |
… | |
… | |
44 | |
44 | |
45 | Uncompress the string (compressed by C<compress>) and return the original |
45 | Uncompress the string (compressed by C<compress>) and return the original |
46 | data. Decompression errors can result in either broken data (there is no |
46 | data. Decompression errors can result in either broken data (there is no |
47 | checksum kept) or a runtime error. |
47 | checksum kept) or a runtime error. |
48 | |
48 | |
|
|
49 | =head2 $serialized = sfreeze $value (simplified freeze) |
|
|
50 | |
|
|
51 | Often there is the need to serialize data into a string. This function does that, by using the Storable |
|
|
52 | module. It does the following transforms: |
|
|
53 | |
|
|
54 | undef (the perl undefined value) |
|
|
55 | => a special cookie (undef'ness is being preserved) |
|
|
56 | IV, NV, PV (i.e. a _plain_ perl scalar): |
|
|
57 | => stays as is when it contains normal text/numbers |
|
|
58 | => gets serialized into a string |
|
|
59 | RV, undef, other funny objects (magical ones for example): |
|
|
60 | => data structure is freeze'd into a string. |
|
|
61 | |
|
|
62 | That is, it tries to leave "normal", human-readable data untouched but |
|
|
63 | still serializes complex data structures into strings. The idea is to keep |
|
|
64 | readability as high as possible, and in cases readability can't be helped |
|
|
65 | anyways, it tries to compress the string. |
|
|
66 | |
|
|
67 | The C<sfreeze> functions will enlarge the original data one byte at most |
|
|
68 | and will only load the Storable method when neccessary. |
|
|
69 | |
|
|
70 | =head2 $serialized = sfreeze_c $value (sfreeze and compress) |
|
|
71 | |
|
|
72 | Similar to C<sfreeze>, but always tries to C<c>ompress the resulting |
|
|
73 | string. This still leaves most small objects (most numbers) untouched. |
|
|
74 | |
|
|
75 | =head2 $serialized = sfreeze_cr $value (sfreeze and compress references) |
|
|
76 | |
|
|
77 | Similar to C<sfreeze>, but tries to C<c>ompress the resulting string |
|
|
78 | unless it's a "simple" string. References for example are not "simple" and |
|
|
79 | as such are being compressed. |
|
|
80 | |
|
|
81 | =head2 $original_data = sthaw $serialized |
|
|
82 | |
|
|
83 | Recreate the original object from it's serialized representation. This |
|
|
84 | function automatically detects all the different sfreeze formats. |
|
|
85 | |
|
|
86 | =head2 Compress::LZF::set_serializer $package, $freeze, $thaw |
|
|
87 | |
|
|
88 | Set the serialize module and functions to use. The default is "Storable", |
|
|
89 | "Storable::net_mstore" and "Storable::mretrieve", which should be fine for |
|
|
90 | most purposes. |
|
|
91 | |
49 | =head1 SEE ALSO |
92 | =head1 SEE ALSO |
50 | |
93 | |
51 | Other Compress::* modules, especially Compress::LZV1 (an older, less |
94 | Other Compress::* modules, especially Compress::LZV1 (an older, less |
52 | speedy module that guarentees only 1 byte overhead worst case) and |
95 | speedy module that guarentees only 1 byte overhead worst case) and |
53 | Compress::Zlib. |
96 | Compress::Zlib. |
… | |
… | |
55 | http://liblzf.plan9.de/ |
98 | http://liblzf.plan9.de/ |
56 | |
99 | |
57 | =head1 AUTHOR |
100 | =head1 AUTHOR |
58 | |
101 | |
59 | This perl extension and the underlying liblzf were written by Marc Lehmann |
102 | This perl extension and the underlying liblzf were written by Marc Lehmann |
60 | <pcg@goof.com> (See also http://liblzf.plan9.de/). |
103 | <schmorp@schmorp.de> (See also http://liblzf.plan9.de/). |
61 | |
104 | |
62 | =head1 BUGS |
105 | =head1 BUGS |
63 | |
106 | |
64 | =cut |
107 | =cut |
65 | |
108 | |
66 | package Compress::LZF; |
109 | package Compress::LZF; |
67 | |
110 | |
68 | require Exporter; |
111 | require Exporter; |
69 | require DynaLoader; |
112 | require DynaLoader; |
70 | |
113 | |
71 | $VERSION = 0.1; |
114 | $VERSION = '1.8'; |
72 | @ISA = qw/Exporter DynaLoader/; |
115 | @ISA = qw/Exporter DynaLoader/; |
73 | %EXPORT_TAGS = ( |
116 | %EXPORT_TAGS = ( |
74 | freeze => [qw(sfreeze sfreeze_cr sfreeze_c sthaw)], |
117 | freeze => [qw(sfreeze sfreeze_cr sfreeze_c sthaw)], |
75 | compress => [qw(compress decompress)], |
118 | compress => [qw(compress decompress)], |
76 | ); |
119 | ); |