1IO::Uncompress::UnLzma(U3s)er Contributed Perl DocumentatIiOo:n:Uncompress::UnLzma(3)
2
3
4

NAME

6       IO::Uncompress::UnLzma - Read lzma files/buffers
7

SYNOPSIS

9           use IO::Uncompress::UnLzma qw(unlzma $UnLzmaError) ;
10
11           my $status = unlzma $input => $output [,OPTS]
12               or die "unlzma failed: $UnLzmaError\n";
13
14           my $z = new IO::Uncompress::UnLzma $input [OPTS]
15               or die "unlzma failed: $UnLzmaError\n";
16
17           $status = $z->read($buffer)
18           $status = $z->read($buffer, $length)
19           $status = $z->read($buffer, $length, $offset)
20           $line = $z->getline()
21           $char = $z->getc()
22           $char = $z->ungetc()
23           $char = $z->opened()
24
25           $data = $z->trailingData()
26           $status = $z->nextStream()
27           $data = $z->getHeaderInfo()
28           $z->tell()
29           $z->seek($position, $whence)
30           $z->binmode()
31           $z->fileno()
32           $z->eof()
33           $z->close()
34
35           $UnLzmaError ;
36
37           # IO::File mode
38
39           <$z>
40           read($z, $buffer);
41           read($z, $buffer, $length);
42           read($z, $buffer, $length, $offset);
43           tell($z)
44           seek($z, $position, $whence)
45           binmode($z)
46           fileno($z)
47           eof($z)
48           close($z)
49

DESCRIPTION

51       WARNING -- This is a Beta release.
52
53       ·    DO NOT use in production code.
54
55       ·    The documentation is incomplete in places.
56
57       ·    Parts of the interface defined here are tentative.
58
59       ·    Please report any problems you find.
60
61       This module provides a Perl interface that allows the reading of lzma
62       files/buffers.
63
64       For writing lzma files/buffers, see the companion module
65       IO::Compress::Lzma.
66

Functional Interface

68       A top-level function, "unlzma", is provided to carry out "one-shot"
69       uncompression between buffers and/or files. For finer control over the
70       uncompression process, see the "OO Interface" section.
71
72           use IO::Uncompress::UnLzma qw(unlzma $UnLzmaError) ;
73
74           unlzma $input => $output [,OPTS]
75               or die "unlzma failed: $UnLzmaError\n";
76
77       The functional interface needs Perl5.005 or better.
78
79   unlzma $input => $output [, OPTS]
80       "unlzma" expects at least two parameters, $input and $output.
81
82       The $input parameter
83
84       The parameter, $input, is used to define the source of the compressed
85       data.
86
87       It can take one of the following forms:
88
89       A filename
90            If the $input parameter is a simple scalar, it is assumed to be a
91            filename. This file will be opened for reading and the input data
92            will be read from it.
93
94       A filehandle
95            If the $input parameter is a filehandle, the input data will be
96            read from it.  The string '-' can be used as an alias for standard
97            input.
98
99       A scalar reference
100            If $input is a scalar reference, the input data will be read from
101            $$input.
102
103       An array reference
104            If $input is an array reference, each element in the array must be
105            a filename.
106
107            The input data will be read from each file in turn.
108
109            The complete array will be walked to ensure that it only contains
110            valid filenames before any data is uncompressed.
111
112       An Input FileGlob string
113            If $input is a string that is delimited by the characters "<" and
114            ">" "unlzma" will assume that it is an input fileglob string. The
115            input is the list of files that match the fileglob.
116
117            See File::GlobMapper for more details.
118
119       If the $input parameter is any other type, "undef" will be returned.
120
121       The $output parameter
122
123       The parameter $output is used to control the destination of the
124       uncompressed data. This parameter can take one of these forms.
125
126       A filename
127            If the $output parameter is a simple scalar, it is assumed to be a
128            filename.  This file will be opened for writing and the
129            uncompressed data will be written to it.
130
131       A filehandle
132            If the $output parameter is a filehandle, the uncompressed data
133            will be written to it.  The string '-' can be used as an alias for
134            standard output.
135
136       A scalar reference
137            If $output is a scalar reference, the uncompressed data will be
138            stored in $$output.
139
140       An Array Reference
141            If $output is an array reference, the uncompressed data will be
142            pushed onto the array.
143
144       An Output FileGlob
145            If $output is a string that is delimited by the characters "<" and
146            ">" "unlzma" will assume that it is an output fileglob string. The
147            output is the list of files that match the fileglob.
148
149            When $output is an fileglob string, $input must also be a fileglob
150            string. Anything else is an error.
151
152            See File::GlobMapper for more details.
153
154       If the $output parameter is any other type, "undef" will be returned.
155
156   Notes
157       When $input maps to multiple compressed files/buffers and $output is a
158       single file/buffer, after uncompression $output will contain a
159       concatenation of all the uncompressed data from each of the input
160       files/buffers.
161
162   Optional Parameters
163       Unless specified below, the optional parameters for "unlzma", "OPTS",
164       are the same as those used with the OO interface defined in the
165       "Constructor Options" section below.
166
167       "AutoClose => 0|1"
168            This option applies to any input or output data streams to
169            "unlzma" that are filehandles.
170
171            If "AutoClose" is specified, and the value is true, it will result
172            in all input and/or output filehandles being closed once "unlzma"
173            has completed.
174
175            This parameter defaults to 0.
176
177       "BinModeOut => 0|1"
178            When writing to a file or filehandle, set "binmode" before writing
179            to the file.
180
181            Defaults to 0.
182
183       "Append => 0|1"
184            The behaviour of this option is dependent on the type of output
185            data stream.
186
187            ·    A Buffer
188
189                 If "Append" is enabled, all uncompressed data will be append
190                 to the end of the output buffer. Otherwise the output buffer
191                 will be cleared before any uncompressed data is written to
192                 it.
193
194            ·    A Filename
195
196                 If "Append" is enabled, the file will be opened in append
197                 mode. Otherwise the contents of the file, if any, will be
198                 truncated before any uncompressed data is written to it.
199
200            ·    A Filehandle
201
202                 If "Append" is enabled, the filehandle will be positioned to
203                 the end of the file via a call to "seek" before any
204                 uncompressed data is written to it.  Otherwise the file
205                 pointer will not be moved.
206
207            When "Append" is specified, and set to true, it will append all
208            uncompressed data to the output data stream.
209
210            So when the output is a filehandle it will carry out a seek to the
211            eof before writing any uncompressed data. If the output is a
212            filename, it will be opened for appending. If the output is a
213            buffer, all uncompressed data will be appened to the existing
214            buffer.
215
216            Conversely when "Append" is not specified, or it is present and is
217            set to false, it will operate as follows.
218
219            When the output is a filename, it will truncate the contents of
220            the file before writing any uncompressed data. If the output is a
221            filehandle its position will not be changed. If the output is a
222            buffer, it will be wiped before any uncompressed data is output.
223
224            Defaults to 0.
225
226       "MultiStream => 0|1"
227            If the input file/buffer contains multiple compressed data
228            streams, this option will uncompress the whole lot as a single
229            data stream.
230
231            Defaults to 0.
232
233       "TrailingData => $scalar"
234            Returns the data, if any, that is present immediately after the
235            compressed data stream once uncompression is complete.
236
237            This option can be used when there is useful information
238            immediately following the compressed data stream, and you don't
239            know the length of the compressed data stream.
240
241            If the input is a buffer, "trailingData" will return everything
242            from the end of the compressed data stream to the end of the
243            buffer.
244
245            If the input is a filehandle, "trailingData" will return the data
246            that is left in the filehandle input buffer once the end of the
247            compressed data stream has been reached. You can then use the
248            filehandle to read the rest of the input file.
249
250            Don't bother using "trailingData" if the input is a filename.
251
252            If you know the length of the compressed data stream before you
253            start uncompressing, you can avoid having to use "trailingData" by
254            setting the "InputLength" option.
255
256   Examples
257       To read the contents of the file "file1.txt.lzma" and write the
258       uncompressed data to the file "file1.txt".
259
260           use strict ;
261           use warnings ;
262           use IO::Uncompress::UnLzma qw(unlzma $UnLzmaError) ;
263
264           my $input = "file1.txt.lzma";
265           my $output = "file1.txt";
266           unlzma $input => $output
267               or die "unlzma failed: $UnLzmaError\n";
268
269       To read from an existing Perl filehandle, $input, and write the
270       uncompressed data to a buffer, $buffer.
271
272           use strict ;
273           use warnings ;
274           use IO::Uncompress::UnLzma qw(unlzma $UnLzmaError) ;
275           use IO::File ;
276
277           my $input = new IO::File "<file1.txt.lzma"
278               or die "Cannot open 'file1.txt.lzma': $!\n" ;
279           my $buffer ;
280           unlzma $input => \$buffer
281               or die "unlzma failed: $UnLzmaError\n";
282
283       To uncompress all files in the directory "/my/home" that match
284       "*.txt.lzma" and store the compressed data in the same directory
285
286           use strict ;
287           use warnings ;
288           use IO::Uncompress::UnLzma qw(unlzma $UnLzmaError) ;
289
290           unlzma '</my/home/*.txt.lzma>' => '</my/home/#1.txt>'
291               or die "unlzma failed: $UnLzmaError\n";
292
293       and if you want to compress each file one at a time, this will do the
294       trick
295
296           use strict ;
297           use warnings ;
298           use IO::Uncompress::UnLzma qw(unlzma $UnLzmaError) ;
299
300           for my $input ( glob "/my/home/*.txt.lzma" )
301           {
302               my $output = $input;
303               $output =~ s/.lzma// ;
304               unlzma $input => $output
305                   or die "Error compressing '$input': $UnLzmaError\n";
306           }
307

OO Interface

309   Constructor
310       The format of the constructor for IO::Uncompress::UnLzma is shown below
311
312           my $z = new IO::Uncompress::UnLzma $input [OPTS]
313               or die "IO::Uncompress::UnLzma failed: $UnLzmaError\n";
314
315       Returns an "IO::Uncompress::UnLzma" object on success and undef on
316       failure.  The variable $UnLzmaError will contain an error message on
317       failure.
318
319       If you are running Perl 5.005 or better the object, $z, returned from
320       IO::Uncompress::UnLzma can be used exactly like an IO::File filehandle.
321       This means that all normal input file operations can be carried out
322       with $z.  For example, to read a line from a compressed file/buffer you
323       can use either of these forms
324
325           $line = $z->getline();
326           $line = <$z>;
327
328       The mandatory parameter $input is used to determine the source of the
329       compressed data. This parameter can take one of three forms.
330
331       A filename
332            If the $input parameter is a scalar, it is assumed to be a
333            filename. This file will be opened for reading and the compressed
334            data will be read from it.
335
336       A filehandle
337            If the $input parameter is a filehandle, the compressed data will
338            be read from it.  The string '-' can be used as an alias for
339            standard input.
340
341       A scalar reference
342            If $input is a scalar reference, the compressed data will be read
343            from $$output.
344
345   Constructor Options
346       The option names defined below are case insensitive and can be
347       optionally prefixed by a '-'.  So all of the following are valid
348
349           -AutoClose
350           -autoclose
351           AUTOCLOSE
352           autoclose
353
354       OPTS is a combination of the following options:
355
356       "AutoClose => 0|1"
357            This option is only valid when the $input parameter is a
358            filehandle. If specified, and the value is true, it will result in
359            the file being closed once either the "close" method is called or
360            the IO::Uncompress::UnLzma object is destroyed.
361
362            This parameter defaults to 0.
363
364       "MultiStream => 0|1"
365            Allows multiple concatenated compressed streams to be treated as a
366            single compressed stream. Decompression will stop once either the
367            end of the file/buffer is reached, an error is encountered
368            (premature eof, corrupt compressed data) or the end of a stream is
369            not immediately followed by the start of another stream.
370
371            This parameter defaults to 0.
372
373       "Prime => $string"
374            This option will uncompress the contents of $string before
375            processing the input file/buffer.
376
377            This option can be useful when the compressed data is embedded in
378            another file/data structure and it is not possible to work out
379            where the compressed data begins without having to read the first
380            few bytes. If this is the case, the uncompression can be primed
381            with these bytes using this option.
382
383       "Transparent => 0|1"
384            If this option is set and the input file/buffer is not compressed
385            data, the module will allow reading of it anyway.
386
387            In addition, if the input file/buffer does contain compressed data
388            and there is non-compressed data immediately following it, setting
389            this option will make this module treat the whole file/bufffer as
390            a single data stream.
391
392            This option defaults to 1.
393
394       "BlockSize => $num"
395            When reading the compressed input data, IO::Uncompress::UnLzma
396            will read it in blocks of $num bytes.
397
398            This option defaults to 4096.
399
400       "InputLength => $size"
401            When present this option will limit the number of compressed bytes
402            read from the input file/buffer to $size. This option can be used
403            in the situation where there is useful data directly after the
404            compressed data stream and you know beforehand the exact length of
405            the compressed data stream.
406
407            This option is mostly used when reading from a filehandle, in
408            which case the file pointer will be left pointing to the first
409            byte directly after the compressed data stream.
410
411            This option defaults to off.
412
413       "Append => 0|1"
414            This option controls what the "read" method does with uncompressed
415            data.
416
417            If set to 1, all uncompressed data will be appended to the output
418            parameter of the "read" method.
419
420            If set to 0, the contents of the output parameter of the "read"
421            method will be overwritten by the uncompressed data.
422
423            Defaults to 0.
424
425       "Strict => 0|1"
426            This option controls whether the extra checks defined below are
427            used when carrying out the decompression. When Strict is on, the
428            extra tests are carried out, when Strict is off they are not.
429
430            The default for this option is off.
431
432   Examples
433       TODO
434

Methods

436   read
437       Usage is
438
439           $status = $z->read($buffer)
440
441       Reads a block of compressed data (the size the the compressed block is
442       determined by the "Buffer" option in the constructor), uncompresses it
443       and writes any uncompressed data into $buffer. If the "Append"
444       parameter is set in the constructor, the uncompressed data will be
445       appended to the $buffer parameter. Otherwise $buffer will be
446       overwritten.
447
448       Returns the number of uncompressed bytes written to $buffer, zero if
449       eof or a negative number on error.
450
451   read
452       Usage is
453
454           $status = $z->read($buffer, $length)
455           $status = $z->read($buffer, $length, $offset)
456
457           $status = read($z, $buffer, $length)
458           $status = read($z, $buffer, $length, $offset)
459
460       Attempt to read $length bytes of uncompressed data into $buffer.
461
462       The main difference between this form of the "read" method and the
463       previous one, is that this one will attempt to return exactly $length
464       bytes. The only circumstances that this function will not is if end-of-
465       file or an IO error is encountered.
466
467       Returns the number of uncompressed bytes written to $buffer, zero if
468       eof or a negative number on error.
469
470   getline
471       Usage is
472
473           $line = $z->getline()
474           $line = <$z>
475
476       Reads a single line.
477
478       This method fully supports the use of of the variable $/ (or
479       $INPUT_RECORD_SEPARATOR or $RS when "English" is in use) to determine
480       what constitutes an end of line. Paragraph mode, record mode and file
481       slurp mode are all supported.
482
483   getc
484       Usage is
485
486           $char = $z->getc()
487
488       Read a single character.
489
490   ungetc
491       Usage is
492
493           $char = $z->ungetc($string)
494
495   getHeaderInfo
496       Usage is
497
498           $hdr  = $z->getHeaderInfo();
499           @hdrs = $z->getHeaderInfo();
500
501       This method returns either a hash reference (in scalar context) or a
502       list or hash references (in array context) that contains information
503       about each of the header fields in the compressed data stream(s).
504
505   tell
506       Usage is
507
508           $z->tell()
509           tell $z
510
511       Returns the uncompressed file offset.
512
513   eof
514       Usage is
515
516           $z->eof();
517           eof($z);
518
519       Returns true if the end of the compressed input stream has been
520       reached.
521
522   seek
523           $z->seek($position, $whence);
524           seek($z, $position, $whence);
525
526       Provides a sub-set of the "seek" functionality, with the restriction
527       that it is only legal to seek forward in the input file/buffer.  It is
528       a fatal error to attempt to seek backward.
529
530       The $whence parameter takes one the usual values, namely SEEK_SET,
531       SEEK_CUR or SEEK_END.
532
533       Returns 1 on success, 0 on failure.
534
535   binmode
536       Usage is
537
538           $z->binmode
539           binmode $z ;
540
541       This is a noop provided for completeness.
542
543   opened
544           $z->opened()
545
546       Returns true if the object currently refers to a opened file/buffer.
547
548   autoflush
549           my $prev = $z->autoflush()
550           my $prev = $z->autoflush(EXPR)
551
552       If the $z object is associated with a file or a filehandle, this method
553       returns the current autoflush setting for the underlying filehandle. If
554       "EXPR" is present, and is non-zero, it will enable flushing after every
555       write/print operation.
556
557       If $z is associated with a buffer, this method has no effect and always
558       returns "undef".
559
560       Note that the special variable $| cannot be used to set or retrieve the
561       autoflush setting.
562
563   input_line_number
564           $z->input_line_number()
565           $z->input_line_number(EXPR)
566
567       Returns the current uncompressed line number. If "EXPR" is present it
568       has the effect of setting the line number. Note that setting the line
569       number does not change the current position within the file/buffer
570       being read.
571
572       The contents of $/ are used to to determine what constitutes a line
573       terminator.
574
575   fileno
576           $z->fileno()
577           fileno($z)
578
579       If the $z object is associated with a file or a filehandle, "fileno"
580       will return the underlying file descriptor. Once the "close" method is
581       called "fileno" will return "undef".
582
583       If the $z object is is associated with a buffer, this method will
584       return "undef".
585
586   close
587           $z->close() ;
588           close $z ;
589
590       Closes the output file/buffer.
591
592       For most versions of Perl this method will be automatically invoked if
593       the IO::Uncompress::UnLzma object is destroyed (either explicitly or by
594       the variable with the reference to the object going out of scope). The
595       exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In these
596       cases, the "close" method will be called automatically, but not until
597       global destruction of all live objects when the program is terminating.
598
599       Therefore, if you want your scripts to be able to run on all versions
600       of Perl, you should call "close" explicitly and not rely on automatic
601       closing.
602
603       Returns true on success, otherwise 0.
604
605       If the "AutoClose" option has been enabled when the
606       IO::Uncompress::UnLzma object was created, and the object is associated
607       with a file, the underlying file will also be closed.
608
609   nextStream
610       Usage is
611
612           my $status = $z->nextStream();
613
614       Skips to the next compressed data stream in the input file/buffer. If a
615       new compressed data stream is found, the eof marker will be cleared and
616       $.  will be reset to 0.
617
618       Returns 1 if a new stream was found, 0 if none was found, and -1 if an
619       error was encountered.
620
621   trailingData
622       Usage is
623
624           my $data = $z->trailingData();
625
626       Returns the data, if any, that is present immediately after the
627       compressed data stream once uncompression is complete. It only makes
628       sense to call this method once the end of the compressed data stream
629       has been encountered.
630
631       This option can be used when there is useful information immediately
632       following the compressed data stream, and you don't know the length of
633       the compressed data stream.
634
635       If the input is a buffer, "trailingData" will return everything from
636       the end of the compressed data stream to the end of the buffer.
637
638       If the input is a filehandle, "trailingData" will return the data that
639       is left in the filehandle input buffer once the end of the compressed
640       data stream has been reached. You can then use the filehandle to read
641       the rest of the input file.
642
643       Don't bother using "trailingData" if the input is a filename.
644
645       If you know the length of the compressed data stream before you start
646       uncompressing, you can avoid having to use "trailingData" by setting
647       the "InputLength" option in the constructor.
648

Importing

650       No symbolic constants are required by this IO::Uncompress::UnLzma at
651       present.
652
653       :all Imports "unlzma" and $UnLzmaError.  Same as doing this
654
655                use IO::Uncompress::UnLzma qw(unlzma $UnLzmaError) ;
656

EXAMPLES

SEE ALSO

659       Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip,
660       IO::Compress::Deflate, IO::Uncompress::Inflate,
661       IO::Compress::RawDeflate, IO::Uncompress::RawInflate,
662       IO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzma,
663       IO::Compress::Xz, IO::Uncompress::UnXz, IO::Compress::Lzop,
664       IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf,
665       IO::Uncompress::AnyInflate, IO::Uncompress::AnyUncompress
666
667       Compress::Zlib::FAQ
668
669       File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
670

AUTHOR

672       This module was written by Paul Marquess, pmqs@cpan.org.
673

MODIFICATION HISTORY

675       See the Changes file.
676
678       Copyright (c) 2005-2010 Paul Marquess. All rights reserved.
679
680       This program is free software; you can redistribute it and/or modify it
681       under the same terms as Perl itself.
682
683
684
685perl v5.12.1                      2010-07-24         IO::Uncompress::UnLzma(3)
Impressum