Subject: | seek bug - another patch and test |
From: karl.forner#gmail.com
Hello,
I also got into trouble with the seek method. Basically it lacks the whence argument to the seek method.
I wrote a simple patch and a simplistic test to contribute if it can help
you.
Here's the patch:
=================================================================
--- Binary.pm 2005-11-18 15:00:54.000000000 +0100
+++ Binary.pm.fixed 2005-11-18 15:00:33.000000000 +0100
@@ -158,12 +158,13 @@
sub seek {
my $self = shift;
my $seek = shift;
+ my $whence = shift || SEEK_SET;
unless ($self->{_is_seekable}) {
carp "FH is not seekable" if $DEBUG;
return 0;
}
- $self->{_fh}->seek($seek) if defined $seek;
+ $self->{_fh}->seek($seek, $whence) if defined $seek;
$self->_init_bits();
return $self->{_fh}->tell();
======================================================
and here's the test: t/00seek.t
=====================================================
#!perl -w
use strict;
use Test::More qw(no_plan);
use File::Binary;
use Data::Dumper;
my $bin = File::Binary->new('t/le.fibonacci.n32.ints');
$bin->set_endian($File::Binary::LITTLE_ENDIAN);
my %pos_2_value;
foreach (1..10) {
my $key = $bin->tell();
$pos_2_value{$key} = $bin->get_si32();
}
foreach my $key (keys %pos_2_value) {
$bin->seek( $key );
is( $bin->get_si32(), $pos_2_value{$key});
}
$bin->close();
==========================================================
Thanks for your work.
Karl Forner