info > Dpkg::Compression::FileHandle

📛 NAME

Dpkg::Compression::FileHandle - class dealing transparently with file compression

🚀 Quick Reference

Use CaseCommandDescription
Create & write to .gz$fh = Dpkg::Compression::FileHandle→new(filename=>'sample.gz'); print $fh "text"; close $fh;Auto‑opens on first write; compression guessed from extension
Open existing .bz2 for reading$fh = Dpkg::Compression::FileHandle→new(); open($fh, '<', 'sample.bz2'); @lines = <$fh>; close $fh;Three‑arg open transparently decompresses
Write .xz with compression level$fh->set_compression('xz'); $fh->set_compression_level(9); $fh->open('out.xz', 'w');Override auto‑detection and set level
Use as a standard filehandleprint $fh "data"; my $char = getc($fh); seek($fh,0,0);Works with print, read, tell, etc. (seek only on uncompressed)
Add extension automatically$fh = Dpkg::Compression::FileHandle→new(filename=>'data', add_comp_ext=>1, compression=>'gzip');Appends .gz to filename; ensures correct extension
Get underlying real filehandle$real_fh = $fh->get_filehandle();Useful for derived classes or direct IO::File operations

📖 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();

📝 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 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 FUNCTIONS

The 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 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.

🔧 PUBLIC METHODS

🧬 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 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

Dpkg::Compression::FileHandle
📛 NAME 🚀 Quick Reference 📖 SYNOPSIS 📝 DESCRIPTION ⚙️ STANDARD FUNCTIONS
📂 FileHandle METHODS
🔧 PUBLIC METHODS 🧬 DERIVED CLASSES 🔄 CHANGES

Generated by phpman v4.9.25-3-gdbaf087 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-06 23:10 @216.73.217.93
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format

^_top_^