ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Compress-LZF/LZF.pm
Revision: 1.25
Committed: Fri Nov 2 12:36:51 2007 UTC (16 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-1_9
Changes since 1.24: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Compress::LZF - extremely light-weight Lempel-Ziv-Free compression
4
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 $serialized = sfreeze_c [4,5,6];
19 $original_data = sthaw $serialized;
20
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 incorporating this module into commercial programs.
29
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 =head2 $compressed = compress $uncompressed
37
38 Try to compress the given string as quickly and as much as possible. In
39 the worst case, the string can enlarge by 1 byte, but that should be the
40 absolute exception. You can expect a 45% compression ratio on large,
41 binary strings.
42
43 =head2 $decompressed = decompress $compressed
44
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
47 checksum kept) or a runtime error.
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
92 =head1 SEE ALSO
93
94 Other Compress::* modules, especially Compress::LZV1 (an older, less
95 speedy module that guarentees only 1 byte overhead worst case) and
96 Compress::Zlib.
97
98 http://liblzf.plan9.de/
99
100 =head1 AUTHOR
101
102 This perl extension and the underlying liblzf were written by Marc Lehmann
103 <schmorp@schmorp.de> (See also http://liblzf.plan9.de/).
104
105 =head1 BUGS
106
107 =cut
108
109 package Compress::LZF;
110
111 require Exporter;
112 require DynaLoader;
113
114 $VERSION = '1.9';
115 @ISA = qw/Exporter DynaLoader/;
116 %EXPORT_TAGS = (
117 freeze => [qw(sfreeze sfreeze_cr sfreeze_c sthaw)],
118 compress => [qw(compress decompress)],
119 );
120
121 Exporter::export_tags('compress');
122 Exporter::export_ok_tags('freeze');
123
124 bootstrap Compress::LZF $VERSION;
125
126 1;
127
128
129
130
131