DESCRIPTION

SWF::BinStream module provides a binary byte and bit data stream. It can handle bit-compressed data such as SWF file.

SWF::BinStream::Read

Provides a read stream. Add the binary data to the stream, and you get byte and bit data. The stream calls a user subroutine when the stream data runs short. get_UI16, get_SI16, get_UI32, and get_SI32 get a number in VAX byte order from the stream. get_bits and get_sbits get the bits from MSB to LSB. get_UI*, get_SI*, and get_string skip the remaining bits in the current byte and read data from the next byte. If you want to skip remaining bits manually, use flush_bits.

METHODS

Creates a read stream. It takes three optional arguments. The first arg is a binary string to set as initial data of the stream. The second is a reference of a subroutine which is called when the stream data runs short. The subroutine is called with two ARGS, the first is $stream itself, and the second is how many bytes wanted. The third arg is SWF version number. Default is 5. It is necessary to set proper version because some SWF tags change their structure by the version number.

$stream->Version

returns SWF version number of the stream.

$stream->add_codec( $codec_name )

Adds stream decoder. Decoder 'Zlib' is only available now.

$stream->add_stream( $binary_data )

Adds binary data to the stream.

$stream->Length

Returns how many bytes remain in the stream.

$stream->tell

Returns how many bytes have been read from the stream.

$stream->get_string( $num )

Returns $num bytes as a string.

$stream->get_UI8

Returns an unsigned byte number.

$stream->get_SI8

Returns a signed byte number.

$stream->get_UI16

Returns an unsigned word (2 bytes) number.

$stream->get_SI16

Returns a signed word (2 bytes) number.

$stream->get_UI32

Returns an unsigned double word (4 bytes) number.

$stream->get_SI32

Returns a signed double word (4 bytes) number.

$stream->get_bits( $num )

Returns the $num bit unsigned number.

$stream->get_sbits( $num )

Returns the $num bit signed number.

$stream->lookahead_string( $offset, $num )

$stream->lookahead_UI8( $offset )

$stream->lookahead_SI8( $offset )

$stream->lookahead_UI16( $offset )

$stream->lookahead_SI16( $offset )

$stream->lookahead_UI32( $offset )

$stream->lookahead_SI32( $offset )

Returns the stream data $offset bytes ahead of the current read point. The read pointer does not move.

$stream->flush_bits

Skips the rest bits in the byte and aligned read pointer to the next byte. It does not anything when the read pointer already byte-aligned.

SWF::BinStream::Write

Provides a write stream. Write byte and bit data, then get the stream data as binary string using flush_stream. autoflush requests to the stream to automatically flush the stream and call a user subroutine. set_UI16, set_SI16, set_UI32, and set_SI32 write a number in VAX byte order to the stream. set_bits and set_sbits write the bits from MSB to LSB. set_UI*, set_SI*, and set_string set the rest bits in the last byte to 0 and write data to the next byte boundary. If you want to write bit data and align the write pointer to byte boundary, use flush_bits.

METHODS

SWF::BinStream::Write->new( [$version] )

Creates a write stream. One optional argument is SWF version number. Default is 5. It is necessary to set proper version because some SWF tags change their structure by the version number.

$stream->Version( [$version] )

returns SWF version number of the stream. You can change the version before you write data to the stream.

$stream->add_codec( $codec_name )

Adds stream encoder. Encoder 'Zlib' is only available now.

$stream->autoflush( $size, \&callback_when_flush )

Requests to the stream to automatically flush the stream and call sub with the stream data when the stream size becomes larger than $size bytes.

$stream->flush_stream( [$size] )

Flushes the stream and returns the stream data. Call with $size, it returns $size bytes from the stream. When call without arg or with larger $size than the stream data size, it returns all data including the last bit data ( by calling flush_bits internally).

$stream->flush_bits

Sets the rest bits in the last byte to 0, and aligns write pointer to the next byte boundary.

$stream->Length

Returns how many bytes remain in the stream.

$stream->tell

Returns how many bytes have written.

$stream->mark( [$key, [$obj]] )

Keeps current tell number with $key and $obj. When called without $obj, it returns tell number associated with $key and a list of tell number and object in scalar and list context, respectively. When called without any parameter, it returns mark list ( KEY1, [ TELL_NUMBER1, OBJ1 ], KEY2, [...).

$stream->sub_stream

Creates temporaly sub stream. When flush_stream the sub stream, it's data and marks are written to the parent stream and the sub stream is freed.

As a valued partner and proud supporter of MetaCPAN, StickerYou is
happy to offer a 10% discount on all Custom Stickers,
Business Labels, Roll Labels,
Vinyl Lettering or Custom Decals. StickerYou.com
is your one-stop shop to make your business stick.
Use code METACPAN10 at checkout to apply your discount.