info > Dpkg::Compression::FileHandle

📖 NAME

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

🚀 Quick Reference

Use Case Command Description
🔧 Create filehandle with auto-detection Dpkg::Compression::FileHandle->new(filename => 'sample.gz') Opens file with compression guessed from extension
📝 Write compressed file print $fh "Something\n"; close $fh; Write data to a compressed filehandle
📖 Read compressed file @lines = <$fh>; Read all lines from a compressed file
⚙️ Set explicit compression $fh->set_compression('gzip') Override auto-detection with a specific method
📏 Set compression level $fh->set_compression_level(9) Adjust the compression ratio/speed
🔗 Get underlying filehandle $real_fh = $fh->get_filehandle() Retrieve the raw filehandle for advanced operations
🔐 Ensure open with mode $fh->ensure_open('w') Open file if not already open, error if mode mismatch

📝 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

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

Dpkg::Compression::FileHandle
📖 NAME 🚀 Quick Reference 📝 SYNOPSIS 📚 DESCRIPTION 🛠️ STANDARD FUNCTIONS 🔧 FileHandle METHODS 📋 PUBLIC METHODS 🧬 DERIVED CLASSES 📜 CHANGES
📌 Version 1.01 (dpkg 1.17.11) 📌 Version 1.00 (dpkg 1.15.6)

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-27 04:30 @216.73.217.85
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!