Bitstream¶
In order to implement the functionality that 010 editor has of treating
the entire stream as a bitstream, a stream-wrapping class (pfp.bitwrap.BitwrappedStream) was made
to allow a normal stream to tread like a limited bit stream.
This may be useful in other applications outside of pfp.
BitwrappedStream Reference Documentation¶
-
class
pfp.bitwrap.BitwrappedStream(stream)[source]¶ A stream that wraps other streams to provide bit-level access
-
is_eof()[source]¶ Return if the stream has reached EOF or not without discarding any unflushed bits
Returns: True/False
-
read(num)[source]¶ Read
numnumber of bytes from the stream. Note that this will automatically resets/ends the current bit-reading if it does not end on an even byte ANDself.paddedis True. Ifself.paddedis True, then the entire stream is treated as a bitstream.Num: number of bytes to read Returns: the read bytes, or empty string if EOF has been reached
-
read_bits(num)[source]¶ Read
numnumber of bits from the streamNum: number of bits to read Returns: a list of numbits, or an empty list if EOF has been reached
-
seek(pos, seek_type=0)[source]¶ Seek to the specified position in the stream with seek_type. Unflushed bits will be discarded in the case of a seek.
The stream will also keep track of which bytes have and have not been consumed so that the dom will capture all of the bytes in the stream.
Pos: offset Seek_type: direction Returns: TODO
-
tell()[source]¶ Return the current position in the stream (ignoring bit position)
Returns: int for the position in the stream
-
tell_bits()[source]¶ Return the number of bits into the stream since the last whole byte.
Returns: int
-