|
NAMEDpkg::Compression::FileHandle - object dealing transparently with file compressionSYNOPSISuse 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 an object 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 object inherits from IO::File so all methods that work on this object should work for Dpkg::Compression::FileHandle too. There may be exceptions though.PUBLIC METHODS
DERIVED OBJECTSIf you want to create an object 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; } CHANGESVersion 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.
Visit the GSP FreeBSD Man Page Interface. |