|
NAMEFile::Binary - Binary file reading moduleSYNOPSISuse 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 DESCRIPTIONFile::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. METHODSnewPass in either a file name or something which isa an IO::Handle.openPass 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. seekSeek 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. tellReturn 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_flushTo flush or not to flush. That is the questionset_endianSet 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_bytesGet an arbitary number of bytes from the file.put_bytesWrite some bytesget_ui8 get_si8 put_ui8 put_si8read or write signed or unsigned 8 bit integersget_ui16 get_si16 put_ui16 put_si16read or write signed or unsigned 16 bit integersget_ui32 get_s32 put_ui32 put_si32read or write signed or unsigned 32 bit integersguess_endianGuess the endianness of this system. Returns either $LITTLE_ENDIAN or $BIG_ENDIANcloseClose the file up. The File::Binary object will then be useless until you open up another file;BUGSCan'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 WistowDistributed 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 AUTHORCopyright 2003, Simon Wistow <simon@thegestalt.org>
Visit the GSP FreeBSD Man Page Interface. |