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¶
A stream that wraps other streams to provide bit-level access
Close the stream
Flush the stream
Return if the stream has reached EOF or not without discarding any unflushed bits
Return if the stream is a tty
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 AND
self.paddedis True. If
self.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
numnumber of bits from the stream
Num: number of bits to read Returns: a list of
numbits, or an empty list if EOF has been reached
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
Return the size of the stream, or -1 if it cannot be determined.
Return the current position in the stream (ignoring bit position)
Returns: int for the position in the stream
Return an IntervalTree of unconsumed ranges, of the format (start, end] with the end value not being included
Write data to the stream
Data: the data to write to the stream Returns: None
Write the bits to the stream.
Add the bits to the existing unflushed bits and write complete bytes to the stream.
Convert the bit list into bytes. (Assumes bits is a list whose length is a multiple of 8)
Convert a byte into bits
Convert bytes to a list of bits