GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
File::Binary(3) User Contributed Perl Documentation File::Binary(3)

File::Binary - Binary file reading module

    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

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.

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

    $BIG_ENDIAN 
    $LITTLE_ENDIAN 
    $NATIVE_ENDIAN

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 <simon@thegestalt.org>
2008-04-01 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.