jdv has asked for the wisdom of the Perl Monks concerning the following question:
I'm observing an odd interaction of my module with Digest::MD5 that I haven't been able to figure out.
I'm implementing a read/write interface to a gzip variant using tied filehandles, with full seek/read/readline/tell support. I'm in the testing phase and nearly all of the tests I'm throwing at it seem to be working (basically performing exactly the same combinations of seek, read, <>, etc, on both my tied filehandle object (with the compressed file loaded) and a regular Perl filehandle opened on the uncompressed version, and comparing the output).
The one exception at this point is when I try to provide my tied filehandle to Digest::MD5's addfile() method. This doesn't work:
my $fh = B2B::BGZF::Reader->new_filehandle( $fn_bgzf ); my $hex = Digest::MD5->new()->addfile($fh)->hexdigest; print $hex, "\n"; # prints d41d8cd98f00b204e9800998ecf8427e
The test returns almost immediately and it appears the hash returned is that of an empty string, so clearly the file is not actually being read. However, this works as expected:
my $fh = B2B::BGZF::Reader->new_filehandle( $fn_bgzf ); my $d = Digest::MD5->new(); my $buf = ''; $d->add($buf) while ( read $fh, $buf, 4096 ); my $hex = $d->hexdigest; print $hex, "\n"; # prints the expected sum
It also works fine if I run the original code but substitute the pure-Perl module (although painfully slowly):
my $fh = B2B::BGZF::Reader->new_filehandle( $fn_bgzf ); my $hex = Digest::Perl::MD5->new()->addfile($fh)->hexdigest; print $hex, "\n"; # prints the expected sum
I additionally tried it with Digest::SHA, and that works fine too:
my $fh = B2B::BGZF::Reader->new_filehandle( $fn_bgzf ); my $hex = Digest::SHA->new(1)->addfile($fh)->hexdigest; print $hex, "\n"; # prints the expected sum
Basically, I have only been able to observe the issue when using my module with the XS implementation of Digest::MD5. Debugging is difficult because I'm not sure what code is actually being called (apparently not the addfile() method of Digest::base or any other actual perl code I can find on my system). I have no problem just using the explicit read()/add() form with Digest::MD5, but if this is an indication of a subtle bug in my code I'd like to work it out - I'm just not sure how to do so.
Any help with understanding what Digest::MD5::addfile() is actually calling under the hood or what might be going on here would be greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Digest::MD5 addfile() w/ tied filehandle
by jdv (Sexton) on Sep 01, 2015 at 21:18 UTC | |
by Anonymous Monk on Sep 02, 2015 at 02:36 UTC | |
by Anonymous Monk on Sep 02, 2015 at 02:37 UTC | |
|
Re: Digest::MD5 addfile() w/ tied filehandle
by u65 (Chaplain) on Aug 30, 2015 at 13:26 UTC | |
by jdv (Sexton) on Aug 30, 2015 at 20:03 UTC | |
|
Re: Digest::MD5 addfile() w/ tied filehandle
by jdv (Sexton) on Sep 01, 2015 at 16:55 UTC | |
by BrowserUk (Patriarch) on Sep 01, 2015 at 18:28 UTC | |
by jdv (Sexton) on Sep 01, 2015 at 19:07 UTC | |
by BrowserUk (Patriarch) on Sep 01, 2015 at 19:46 UTC | |
|
Re: Digest::MD5 addfile() w/ tied filehandle
by jdv (Sexton) on Sep 04, 2015 at 15:16 UTC |