ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Compress-LZF/LZF.pm
Revision: 1.33
Committed: Sun Aug 25 18:13:26 2013 UTC (10 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-3_7
Changes since 1.32: +34 -10 lines
Log Message:
3.7

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3 root 1.20 Compress::LZF - extremely light-weight Lempel-Ziv-Free compression
4 root 1.1
5     =head1 SYNOPSIS
6    
7     # import compress/decompress functions
8     use Compress::LZF;
9     # the same as above
10     use Compress::LZF ':compress';
11    
12     $compressed = compress $uncompressed_data;
13     $original_data = decompress $compressed;
14    
15     # import sfreeze, sfreeze_cref and sfreeze_c
16     use Compress::LZF ':freeze';
17    
18 root 1.2 $serialized = sfreeze_c [4,5,6];
19     $original_data = sthaw $serialized;
20 root 1.1
21     =head1 DESCRIPTION
22    
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
25     I<some> space but not at the cost of speed. It is ideal for repetitive
26     data as well. The module is self-contained and very small (no large
27     library to be pulled in). It is also free, so there should be no problems
28 root 1.24 incorporating this module into commercial programs.
29 root 1.1
30     I have no idea wether any patents in any countries apply to this
31     algorithm, but at the moment it is believed that it is free from any
32     patents.
33    
34     =head1 FUNCTIONS
35    
36 root 1.33 =over 4
37    
38     =item $compressed = compress $uncompressed
39    
40     =item $compressed = compress_best $uncompressed
41 root 1.1
42     Try to compress the given string as quickly and as much as possible. In
43     the worst case, the string can enlarge by 1 byte, but that should be the
44     absolute exception. You can expect a 45% compression ratio on large,
45     binary strings.
46    
47 root 1.33 The C<compress_best> function uses a different algorithm that is slower
48     but usually achieves better compression.
49    
50     =item $decompressed = decompress $compressed
51 root 1.1
52     Uncompress the string (compressed by C<compress>) and return the original
53     data. Decompression errors can result in either broken data (there is no
54     checksum kept) or a runtime error.
55 root 1.2
56 root 1.33 =item $serialized = sfreeze $value (simplified freeze)
57    
58     =item $serialized = sfreeze_best $value
59 root 1.2
60     Often there is the need to serialize data into a string. This function does that, by using the Storable
61     module. It does the following transforms:
62    
63 root 1.3 undef (the perl undefined value)
64     => a special cookie (undef'ness is being preserved)
65 root 1.2 IV, NV, PV (i.e. a _plain_ perl scalar):
66     => stays as is when it contains normal text/numbers
67     => gets serialized into a string
68     RV, undef, other funny objects (magical ones for example):
69     => data structure is freeze'd into a string.
70    
71     That is, it tries to leave "normal", human-readable data untouched but
72 root 1.3 still serializes complex data structures into strings. The idea is to keep
73     readability as high as possible, and in cases readability can't be helped
74     anyways, it tries to compress the string.
75 root 1.2
76     The C<sfreeze> functions will enlarge the original data one byte at most
77     and will only load the Storable method when neccessary.
78    
79 root 1.33 The C<sfreeze_best> function uses a different algorithm that is slower
80     but usually achieves better compression.
81    
82     =item $serialized = sfreeze_c $value (sfreeze and compress)
83    
84     =item $serialized = sfreeze_c_best $value
85 root 1.2
86     Similar to C<sfreeze>, but always tries to C<c>ompress the resulting
87     string. This still leaves most small objects (most numbers) untouched.
88    
89 root 1.33 The C<sfreeze_c> function uses a different algorithm that is slower
90     but usually achieves better compression.
91    
92     =item $serialized = sfreeze_cr $value (sfreeze and compress references)
93    
94     =item $serialized = sfreeze_cr_best $value
95 root 1.2
96     Similar to C<sfreeze>, but tries to C<c>ompress the resulting string
97     unless it's a "simple" string. References for example are not "simple" and
98     as such are being compressed.
99    
100 root 1.33 The C<sfreeze_cr_best> function uses a different algorithm that is slower
101     but usually achieves better compression.
102    
103     =item $original_data = sthaw $serialized
104 root 1.2
105     Recreate the original object from it's serialized representation. This
106     function automatically detects all the different sfreeze formats.
107 root 1.1
108 root 1.33 =item Compress::LZF::set_serializer $package, $freeze, $thaw
109 root 1.10
110     Set the serialize module and functions to use. The default is "Storable",
111 root 1.20 "Storable::net_mstore" and "Storable::mretrieve", which should be fine for
112 root 1.10 most purposes.
113    
114 root 1.33 =back
115    
116 root 1.1 =head1 SEE ALSO
117    
118     Other Compress::* modules, especially Compress::LZV1 (an older, less
119     speedy module that guarentees only 1 byte overhead worst case) and
120     Compress::Zlib.
121    
122     http://liblzf.plan9.de/
123    
124     =head1 AUTHOR
125    
126     This perl extension and the underlying liblzf were written by Marc Lehmann
127 pcg 1.18 <schmorp@schmorp.de> (See also http://liblzf.plan9.de/).
128 root 1.1
129     =head1 BUGS
130    
131     =cut
132    
133     package Compress::LZF;
134    
135     require Exporter;
136     require DynaLoader;
137    
138 root 1.33 $VERSION = '3.7';
139 root 1.1 @ISA = qw/Exporter DynaLoader/;
140     %EXPORT_TAGS = (
141 root 1.33 freeze => [qw(sfreeze sfreeze_best sfreeze_cr sfreeze_cr_best sfreeze_c sfreeze_c_best sthaw)],
142     compress => [qw(compress compress_best decompress)],
143 root 1.1 );
144    
145     Exporter::export_tags('compress');
146     Exporter::export_ok_tags('freeze');
147    
148     bootstrap Compress::LZF $VERSION;
149    
150     1;
151    
152    
153    
154    
155