.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Dpkg::Compression::FileHandle 3perl" .TH Dpkg::Compression::FileHandle 3perl 2024-03-10 1.22.6 libdpkg-perl .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Dpkg::Compression::FileHandle \- class dealing transparently with file compression .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Dpkg::Compression::FileHandle; \& \& my ($fh, @lines); \& \& $fh = Dpkg::Compression::FileHandle\->new(filename => \*(Aqsample.gz\*(Aq); \& print $fh "Something\en"; \& close $fh; \& \& $fh = Dpkg::Compression::FileHandle\->new(); \& open($fh, \*(Aq>\*(Aq, \*(Aqsample.bz2\*(Aq); \& print $fh "Something\en"; \& close $fh; \& \& $fh = Dpkg::Compression::FileHandle\->new(); \& $fh\->open(\*(Aqsample.xz\*(Aq, \*(Aqw\*(Aq); \& $fh\->print("Something\en"); \& $fh\->close(); \& \& $fh = Dpkg::Compression::FileHandle\->new(filename => \*(Aqsample.gz\*(Aq); \& @lines = <$fh>; \& close $fh; \& \& $fh = Dpkg::Compression::FileHandle\->new(); \& open($fh, \*(Aq<\*(Aq, \*(Aqsample.bz2\*(Aq); \& @lines = <$fh>; \& close $fh; \& \& $fh = Dpkg::Compression::FileHandle\->new(); \& $fh\->open(\*(Aqsample.xz\*(Aq, \*(Aqr\*(Aq); \& @lines = $fh\->getlines(); \& $fh\->close(); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Dpkg::Compression::FileHandle is a class that can be used like any filehandle and that deals transparently with compressed files. By default, the compression scheme is guessed from the filename but you can override this behavior with the method \fBset_compression()\fR. .PP If you don't open the file explicitly, it will be auto-opened on the first read or write operation based on the filename set at creation time (or later with the \fBset_filename()\fR method). .PP Once a file has been opened, the filehandle must be closed before being able to open another file. .SH "STANDARD FUNCTIONS" .IX Header "STANDARD FUNCTIONS" The standard functions acting on filehandles should accept a Dpkg::Compression::FileHandle object transparently including \&\fBopen()\fR (only when using the variant with 3 parameters), \fBclose()\fR, \&\fBbinmode()\fR, \fBeof()\fR, \fBfileno()\fR, \fBgetc()\fR, \fBprint()\fR, \fBprintf()\fR, \fBread()\fR, \&\fBsysread()\fR, \fBsay()\fR, \fBwrite()\fR, \fBsyswrite()\fR, \fBseek()\fR, \fBsysseek()\fR, \fBtell()\fR. .PP Note however that \fBseek()\fR and \fBsysseek()\fR will only work on uncompressed files as compressed files are really pipes to the compressor programs and you can't seek on a pipe. .SH "FileHandle METHODS" .IX Header "FileHandle METHODS" The class inherits from IO::File so all methods that work on this class should work for Dpkg::Compression::FileHandle too. There may be exceptions though. .SH "PUBLIC METHODS" .IX Header "PUBLIC METHODS" .ie n .IP "$fh = Dpkg::Compression::FileHandle\->new(%opts)" 4 .el .IP "\f(CW$fh\fR = Dpkg::Compression::FileHandle\->new(%opts)" 4 .IX Item "$fh = Dpkg::Compression::FileHandle->new(%opts)" Creates a new filehandle supporting on-the-fly compression/decompression. Supported options are "filename", "compression", "compression_level" (see respective set_* functions) and "add_comp_ext". If "add_comp_ext" evaluates to true, then the extension corresponding to the selected compression scheme is automatically added to the recorded filename. It's obviously incompatible with automatic detection of the compression method. .ie n .IP "$fh\->ensure_open($mode, %opts)" 4 .el .IP "\f(CW$fh\fR\->ensure_open($mode, \f(CW%opts\fR)" 4 .IX Item "$fh->ensure_open($mode, %opts)" Ensure the file is opened in the requested mode ("r" for read and "w" for write). The options are passed down to the compressor's \fBspawn()\fR call, if one is used. Opens the file with the recorded filename if needed. If the file is already open but not in the requested mode, then it errors out. .ie n .IP $fh\->set_compression($comp) 4 .el .IP \f(CW$fh\fR\->set_compression($comp) 4 .IX Item "$fh->set_compression($comp)" Defines the compression method used. \f(CW$comp\fR should one of the methods supported by Dpkg::Compression or "none" or "auto". "none" indicates that the file is uncompressed and "auto" indicates that the method must be guessed based on the filename extension used. .ie n .IP $fh\->set_compression_level($level) 4 .el .IP \f(CW$fh\fR\->set_compression_level($level) 4 .IX Item "$fh->set_compression_level($level)" Indicate the desired compression level. It should be a value accepted by the function \fBcompression_is_valid_level()\fR of Dpkg::Compression. .ie n .IP "$fh\->set_filename($name, [$add_comp_ext])" 4 .el .IP "\f(CW$fh\fR\->set_filename($name, [$add_comp_ext])" 4 .IX Item "$fh->set_filename($name, [$add_comp_ext])" Use \f(CW$name\fR as filename when the file must be opened/created. If \&\f(CW$add_comp_ext\fR is passed, it indicates whether the default extension of the compression method must be automatically added to the filename (or not). .ie n .IP "$file = $fh\->\fBget_filename()\fR" 4 .el .IP "\f(CW$file\fR = \f(CW$fh\fR\->\fBget_filename()\fR" 4 .IX Item "$file = $fh->get_filename()" Returns the filename that would be used when the filehandle must be opened (both in read and write mode). This function errors out if "add_comp_ext" is enabled while the compression method is set to "auto". The returned filename includes the extension of the compression method if "add_comp_ext" is enabled. .ie n .IP "$ret = $fh\->\fBuse_compression()\fR" 4 .el .IP "\f(CW$ret\fR = \f(CW$fh\fR\->\fBuse_compression()\fR" 4 .IX Item "$ret = $fh->use_compression()" Returns "0" if no compression is used and the compression method used otherwise. If the compression is set to "auto", the value returned depends on the extension of the filename obtained with the \fBget_filename()\fR method. .ie n .IP "$real_fh = $fh\->\fBget_filehandle()\fR" 4 .el .IP "\f(CW$real_fh\fR = \f(CW$fh\fR\->\fBget_filehandle()\fR" 4 .IX Item "$real_fh = $fh->get_filehandle()" Returns the real underlying filehandle. Useful if you want to pass it along in a derived class. .SH "DERIVED CLASSES" .IX Header "DERIVED CLASSES" If you want to create a class that inherits from Dpkg::Compression::FileHandle you must be aware that the object is a reference to a GLOB that is returned by \fBSymbol::gensym()\fR and as such it's not a HASH. .PP You can store internal data in a hash but you have to use \&\f(CW\*(C`*$self\-\*(C'\fR{...}> to access the associated hash like in the example below: .PP .Vb 4 \& sub set_option { \& my ($self, $value) = @_; \& *$self\->{option} = $value; \& } .Ve .SH CHANGES .IX Header "CHANGES" .SS "Version 1.01 (dpkg 1.17.11)" .IX Subsection "Version 1.01 (dpkg 1.17.11)" New argument: \f(CW$fh\fR\->\fBensure_open()\fR accepts an \f(CW%opts\fR argument. .SS "Version 1.00 (dpkg 1.15.6)" .IX Subsection "Version 1.00 (dpkg 1.15.6)" Mark the module as public.