Dpkg::Compression::FileHandle - Online Linux Manual PageSection : 3perl
Updated : 2021-04-13
Source : 1.20.9
Note : libdpkg-perl

NAMEDpkg::Compression::FileHandle − class dealing transparently with file compression

SYNOPSIS​ use Dpkg::Compression::FileHandle; ​ ​ my ($fh, @lines); ​ ​ $fh = Dpkg::Compression::FileHandle−>new(filename => 'sample.gz'); ​ print $fh "Something\n"; ​ close $fh; ​ ​ $fh = Dpkg::Compression::FileHandle−>new(); ​ open($fh, '>', 'sample.bz2'); ​ print $fh "Something\n"; ​ close $fh; ​ ​ $fh = Dpkg::Compression::FileHandle−>new(); ​ $fh−>open('sample.xz', 'w'); ​ $fh−>print("Something\n"); ​ $fh−>close(); ​ ​ $fh = Dpkg::Compression::FileHandle−>new(filename => 'sample.gz'); ​ @lines = <$fh>; ​ close $fh; ​ ​ $fh = Dpkg::Compression::FileHandle−>new(); ​ open($fh, '<', 'sample.bz2'); ​ @lines = <$fh>; ​ close $fh; ​ ​ $fh = Dpkg::Compression::FileHandle−>new(); ​ $fh−>open('sample.xz', 'r'); ​ @lines = $fh−>getlines(); ​ $fh−>close();

DESCRIPTIONDpkg::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 behaviour with the method set_compression. 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 set_filename method). Once a file has been opened, the filehandle must be closed before being able to open another file.

STANDARD FUNCTIONSThe standard functions acting on filehandles should accept a Dpkg::Compression::FileHandle object transparently including ​open (only when using the variant with 3 parameters), close, ​binmode, eof, fileno, getc, print, printf, read, ​sysread, say, write, syswrite, seek, sysseek, tell. Note however that seek and sysseek will only work on uncompressed files as compressed files are really pipes to the compressor programs and you can't seek on a pipe.

FileHandle METHODSThe 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.

PUBLIC METHODS$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. $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 spawn() 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. $fh>set_compression($comp) Defines the compression method used. $comp 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. $fh>set_compression_level($level) Indicate the desired compression level. It should be a value accepted by the function compression_is_valid_level of Dpkg::Compression. $fh>set_filename($name, [$add_comp_ext]) Use $name as filename when the file must be opened/created. If ​$add_comp_ext is passed, it indicates whether the default extension of the compression method must be automatically added to the filename (or not). $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. $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 get_filename method. $real_fh = $fh>get_filehandle() Returns the real underlying filehandle. Useful if you want to pass it along in a derived class.

DERIVED CLASSESIf 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 Symbol::gensym() and as such it's not a HASH. You can store internal data in a hash but you have to use ​*$self−{...}> to access the associated hash like in the example below: ​ sub set_option { ​ my ($self, $value) = @_; ​ *$self−>{option} = $value; ​ }

CHANGES

Version 1.01 (dpkg 1.17.11)New argument: $fh>ensure_open() accepts an %opts argument.

Version 1.00 (dpkg 1.15.6)Mark the module as public.
0
Johanes Gumabo
Data Size   :   19,466 byte
man-Dpkg::Compression::FileHandle.3perlBuild   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   2 / 184,532
Visitor ID   :     :  
Visitor IP   :   3.137.170.76   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.

ERROR : Need New Coding :         (parse_manual_page_|249|Dpkg::Compression::FileHandle.3perl|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\| )         (htmlprn|149|Dpkg::Compression::FileHandle.3perl|36/37|.el══─{─══. ds --  —  |.el══─{─══. ds -- \|\(em\| )         (parse_manual_page_|249|Dpkg::Compression::FileHandle.3perl|43|br══─}─══|'br══─}─══ )         (htmlprn|149|Dpkg::Compression::FileHandle.3perl|43|'br══─}─══ |'br══─}─══ )