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


Manual Reference Pages  -  FILE::BINARY (3)

.ds Aq ’

NAME

File::Binary - Binary file reading module

CONTENTS

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

<B>File::BinaryB> 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.

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

Seek to a position.

Return our current position. If our file handle is not <B>ISA IO::SeekableB> it will return 0 and, if <B>B>$File::Binary::DEBUG<B>B> 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.

    tell

Return our current position. If our file handle is not <B>ISA IO::SeekableB> then it will return 0 and, if <B>B>$File::Binary::DEBUG<B>B> 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>
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 FILE::BINARY (3) 2008-04-01

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