Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the OO interface? #9

Open
XSven opened this issue Feb 10, 2020 · 2 comments
Open

How to use the OO interface? #9

XSven opened this issue Feb 10, 2020 · 2 comments
Assignees

Comments

@XSven
Copy link

XSven commented Feb 10, 2020

Although I have read the documentation of IO::Compress::Gzip, it is unclear to me how the following functional call

gzip($inputFile => $outputFilehandle, {Strict => 0}) or die "gzip failed: $GzipError\n";

could be translated into an OO approach. $inputFile is a filename. $outputFilehandle is a raw read+write filehandle.

Furthermore I would like to know which instance(object) method I could use to access the header information of the zip archive. I have seen IO::Uncompress::Gunzip::getHeaderInfo() but I cannot believe that no such method exists for a gzip object itself because such an object should known how it has created the zip archive including its header.

@pmqs
Copy link
Owner

pmqs commented Feb 13, 2020

Although I have read the documentation of IO::Compress::Gzip, it is unclear to me how the following functional call

gzip($inputFile => $outputFilehandle, {Strict => 0}) or die "gzip failed: $GzipError\n";

could be translated into an OO approach. $inputFile is a filename. $outputFilehandle is a raw read+write filehandle.

here is the equivalent OO

use IO::Compress::Gzip qw($GzipError) ;

my $inputFile = "/tmp/x";

my $gz = new IO::Compress::Gzip $outputFilehandle, Strict =>0
    or die "Cannot create gzip object: $GzipError\n";

open my $fh, '<', $inputFile
    or die "Cannot open $inputFile: $!\n" ;

while (read($fh, my $buffer, 1024 * 16))
{
    $gz->write($buffer);
}
$gz->close();

Furthermore I would like to know which instance(object) method I could use to access the header information of the zip archive. I have seen IO::Uncompress::Gunzip::getHeaderInfo() but I cannot believe that no such method exists for a gzip object itself because such an object should known how it has created the zip archive including its header.

There is no public interface to access the gzip header in IO::Compress::Gzip because I've never seen the need. Can you explain the use-case you want it for?

@XSven
Copy link
Author

XSven commented Feb 13, 2020

To be honest, the OO equivalent disappoints me. I would have expected somethink like

$gz->compress($inputFile);

that means an instance(object) method that has one argument, that is the input file.

We could consider this

How do i tell in Perl what the size of a file inside a gzip archive is without unpacking the whole file?

or the question: What is the equivalent of gzip --list as a use-case? But our use-case that has brought us to the above stackoverflow article was this:

We have used the functional interface of IO::Compress::Gzip to zip an input file. Due to a race condition (a bug at our end:-() there was a discrepancy between the content of the original input file and the zip file. The zip file was not(!) corrupt but after unzipping the zip file it was different from original input file due to the race condition. We thought it would be a good idea to log the compressed and the uncompressed file size (ISIZE) from the perspective of IO::Compress::Gzip. We don't wanted to make extra stat() calls before and/or after the crompress action. We wanted the compress action(object) to provide a feedback.

Thx

@pmqs pmqs self-assigned this Feb 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants