File::Binary - Binary file reading module
use File::Binary qw($BIG_ENDIAN $LITTLE_ENDIAN $NATIVE_ENDIAN);
my $fb = File::Binary->new("myfile");
$fb->set_endian($BIG_ENDIAN); # force endianness
# do what they say on the tin
# etc etc
File::Binary is a Binary file reading module, hence the name, and was originally used to write a suite of modules for manipulating Macromedia SWF files.
However it's grown beyond that and now actually, err, works. And is generalised. And EVERYTHING! Yay!
It has methods for reading and writing signed and unsigned 8, 16 and 32 bit integers, at some point in the future I'll figure out a way of putting in methods for >32bit integers nicely but until then, patches welcome.
It hasn't retained backwards compatability with the old version of this module for cleanliness sakes and also because the old interface was pretty braindead.
Pass in either a file name or something which isa an IO::Handle.
Will try and set binmode for the handle on if possible (i.e if the object has a binmode method) otherwise you should do it yourself.
Seek to a position.
Return our current position. If our file handle is not ISA IO::Seekable it will return 0 and, if $File::Binary::DEBUG is set to 1, there will be a warning.
You can optionally pass a whence option in the same way as the builtin Perl seek() method. It defaults to SEEK_SET.
Returns the current file position.
Return our current position. If our file handle is not ISA IO::Seekable then it will return 0 and, if $File::Binary::DEBUG is set to 1, there will be a warning.
To flush or not to flush. That is the question
Set the how the module reads files. The options are
NATIVE will deduce the endianess of the current system.
Get an arbitary number of bytes from the file.
Write some bytes
read or write signed or unsigned 8 bit integers
read or write signed or unsigned 16 bit integers
read or write signed or unsigned 32 bit integers
Guess the endianness of this system. Returns either $LITTLE_ENDIAN or $BIG_ENDIAN
Close the file up. The File::Binary object will then be useless until you open up another file;
Can't do numbers greater than 32 bits.
Can't extract Floating Point or Fixed Point numbers.
Can't extract null terminated strings.
Needs tests for seeking and telling.
(c)opyright 2002, Simon Wistow
Distributed under the same terms as Perl itself.
This software is under no warranty and will probably ruin your life, kill your friends, burn your house and bring about the apocalypse
Copyright 2003, Simon Wistow <email@example.com>
To install File::Binary, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.