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

OO Interface

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

Methods

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

Importing

664       No symbolic constants are required by this IO::Uncompress::UnLzma at
665       present.
666
667       :all Imports "unlzma" and $UnLzmaError.  Same as doing this
668
669                use IO::Uncompress::UnLzma qw(unlzma $UnLzmaError) ;
670

EXAMPLES

SEE ALSO

673       Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip,
674       IO::Compress::Deflate, IO::Uncompress::Inflate,
675       IO::Compress::RawDeflate, IO::Uncompress::RawInflate,
676       IO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzma,
677       IO::Compress::Xz, IO::Uncompress::UnXz, IO::Compress::Lzip,
678       IO::Uncompress::UnLzip, IO::Compress::Lzop, IO::Uncompress::UnLzop,
679       IO::Compress::Lzf, IO::Uncompress::UnLzf, IO::Compress::Zstd,
680       IO::Uncompress::UnZstd, IO::Uncompress::AnyInflate,
681       IO::Uncompress::AnyUncompress
682
683       IO::Compress::FAQ
684
685       File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
686

AUTHOR

688       This module was written by Paul Marquess, "pmqs@cpan.org".
689

MODIFICATION HISTORY

691       See the Changes file.
692
694       Copyright (c) 2005-2019 Paul Marquess. All rights reserved.
695
696       This program is free software; you can redistribute it and/or modify it
697       under the same terms as Perl itself.
698
699
700
701perl v5.30.0                      2019-08-12         IO::Uncompress::UnLzma(3)
Impressum