NAME

File::Binary - Binary file reading module

SYNOPSIS

    use File::Binary qw($BIG_ENDIAN $LITTLE_ENDIAN $NATIVE_ENDIAN);
    my $fb = File::Binary->new("myfile");
    
    $fb->get_ui8();
    $fb->get_ui16();
    $fb->get_ui32();
    $fb->get_si8();
    $fb->get_si16();
    $fb->get_si32();
    $fb->close();
    $fb->open(">newfile");
    $fb->put_ui8(255);
    $fb->put_ui16(65535);
    $fb->put_ui32(4294967295);
    $fb->put_si8(-127);
    $fb->put_si16(-32767);
    $fb->put_si32(-2147483645);
    
    $fb->close();
    $fb->open(IO::Scalar->new($somedata));
    $fb->set_endian($BIG_ENDIAN); # force endianness
    # do what they say on the tin
    $fb->seek($pos);
    $fb->tell();
    # etc etc

DESCRIPTION

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.

METHODS

new

Pass in either a file name or something which isa an IO::Handle.

open

Pass in either a file name or something which isa an IO::Handle.

seek

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.

Returns the current file position.

tell

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.

set_flush

To flush or not to flush. That is the question

set_endian

Set the how the module reads files. The options are

    $BIG_ENDIAN 
    $LITTLE_ENDIAN 
    $NATIVE_ENDIAN

NATIVE will deduce the endianess of the current system.

get_bytes

Get an arbitary number of bytes from the file.

put_bytes

Write some bytes

get_ui8 get_si8 put_ui8 put_si8

read or write signed or unsigned 8 bit integers

get_ui16 get_si16 put_ui16 put_si16

read or write signed or unsigned 16 bit integers

get_ui32 get_s32 put_ui32 put_si32

read or write signed or unsigned 32 bit integers

guess_endian

Guess the endianness of this system. Returns either $LITTLE_ENDIAN or $BIG_ENDIAN

close Close the file up. The File::Binary object will then be useless until you open up another file;

BUGS

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.

COPYING

(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

AUTHOR

Copyright 2003, Simon Wistow <simon@thegestalt.org>