File Coverage

blib/lib/Data/ParseBinary/Stream/File.pm
Criterion Covered Total %
statement 31 36 86.1
branch 2 2 100.0
condition n/a
subroutine 12 15 80.0
pod n/a
total 45 53 84.9


line stmt bran cond sub pod time code
1 5     5   24 use strict;
  5         9  
  5         145  
2 5     5   24 use warnings;
  5         5  
  5         2843  
3            
4             package Data::ParseBinary::Stream::FileReader;
5             our @ISA = qw{Data::ParseBinary::Stream::Reader};
6            
7             __PACKAGE__->_registerStreamType("File");
8            
9             sub new {
10 14     14   29 my ($class, $fh) = @_;
11 14         45 my $self = {
12             handle => $fh,
13             };
14 14         87 return bless $self, $class;
15             }
16            
17             sub ReadBytes {
18 4710     4710   6271 my ($self, $count) = @_;
19 4710         6170 my $buf = '';
20 4710         10867 while ((my $buf_len = length($buf)) < $count) {
21 4664         12141 my $bytes_read = read($self->{handle}, $buf, $count - $buf_len, $buf_len);
22 4664 100       16982 die "Error: End of file" if $bytes_read == 0;
23             }
24 4707         15925 return $buf;
25             }
26            
27             sub ReadBits {
28 0     0   0 my ($self, $bitcount) = @_;
29 0         0 return $self->_readBitsForByteStream($bitcount);
30             }
31            
32             sub tell {
33 149     149   202 my $self = shift;
34 149         475 return CORE::tell($self->{handle});
35             }
36            
37             sub seek {
38 173     173   246 my ($self, $newpos) = @_;
39 173         1479 CORE::seek($self->{handle}, $newpos, 0);
40             }
41            
42 431     431   1198 sub isBitStream { return 0 };
43            
44             package Data::ParseBinary::Stream::FileWriter;
45             our @ISA = qw{Data::ParseBinary::Stream::Writer};
46            
47             __PACKAGE__->_registerStreamType("File");
48            
49             sub new {
50 1     1   2 my ($class, $fh) = @_;
51 1         4 my $self = {
52             handle => $fh,
53             };
54 1         6 return bless $self, $class;
55             }
56            
57             sub WriteBytes {
58 2     2   4 my ($self, $data) = @_;
59 2         2 print { $self->{handle} } $data;
  2         20  
60             }
61            
62             sub WriteBits {
63 0     0   0 my ($self, $bitdata) = @_;
64 0         0 return $self->_writeBitsForByteStream($bitdata);
65             }
66            
67             sub tell {
68 2     2   5 my $self = shift;
69 2         12 return CORE::tell($self->{handle});
70             }
71            
72             sub seek {
73 4     4   7 my ($self, $newpos) = @_;
74 4         85 CORE::seek($self->{handle}, $newpos, 0);
75             }
76            
77             sub Flush {
78 2     2   7 my $self = shift;
79             }
80            
81 0     0     sub isBitStream { return 0 };
82            
83            
84             1;