3.1.9.8. Stream

class PyDvi.Tools.Stream.AbstractStream[source]

Bases: object

Abstract class to read DVI, PK, TFM and VF streams.

The followings methods are abstracts:

and must be implemented in subclass.

In the followings methods, the position argument is used to specify a position in the stream for the read operation. If position is not None, it seeks to the specified position before to read the stream else it reads from the current position. See also read_bytes().

read(number_of_bytes)[source]

Read n bytes from the current position.

read_bcpl(position=None)[source]

Read a BCPL string.

The BCPL string format comes from the Basic Combined Programming Language. The length of the string is given by the first byte, thus its length is limited to 256 characters.

read_big_endian_number(number_of_bytes, signed=False, position=None)[source]

Read a signed or an unsigned integer encoded in big endian order with number_of_bytes bytes, cf. read_bytes().

read_byte_numbers(number_of_bytes, position=None)[source]

Read number_of_bytes times 8-bit unsigned integers, cf. read_bytes().

read_bytes(number_of_bytes, position=None)[source]

Read number_of_bytes bytes from the optional position or the current position. If position, it seeks to the specified position and thus change the current position in the stream.

read_fix_word(position=None)[source]

Read a fix word.

read_four_byte_numbers(position=None)[source]

Read four 8-bit unsigned integers, cf. read_bytes().

read_signed_byte1(position=None)[source]

Read a 1-byte signed integer, cf. read_big_endian_number().

read_signed_byte2(position=None)[source]

Read a 2-byte signed integer, cf. read_big_endian_number().

read_signed_byte3(position=None)[source]

Read a 3-byte signed integer, cf. read_big_endian_number().

read_signed_byte4(position=None)[source]

Read a 4-byte signed integer, cf. read_big_endian_number().

read_signed_byten = (<function read_signed_byte1 at 0x3d94ed8>, <function read_signed_byte2 at 0x3d94f50>, <function read_signed_byte3 at 0x3da6050>, <function read_signed_byte4 at 0x3da60c8>)

This tuple permits to get the read_signed_byte method with the number of bytes as index.

read_three_byte_numbers(position=None)[source]

Read three 8-bit unsigned integers, cf. read_bytes().

read_unsigned_byte1(position=None)[source]

Read a 1-byte unsigned integer, cf. read_big_endian_number().

read_unsigned_byte2(position=None)[source]

Read a 2-byte unsigned integer, cf. read_big_endian_number().

read_unsigned_byte3(position=None)[source]

Read a 3-byte unsigned integer, cf. read_big_endian_number().

read_unsigned_byte4(position=None)[source]

Read a 4-byte unsigned integer, cf. read_big_endian_number().

read_unsigned_byten = (<function read_unsigned_byte1 at 0x3da6140>, <function read_unsigned_byte2 at 0x3da61b8>, <function read_unsigned_byte3 at 0x3da6230>, <function read_unsigned_byte4 at 0x3da62a8>)

This tuple permits to get the read_unsigned_byte method with the number of bytes as index.

seek(postion, whence)[source]

Seek to position.

tell()[source]

Tell the current position.

class PyDvi.Tools.Stream.StandardStream[source]

Bases: PyDvi.Tools.Stream.AbstractStream

Abstract stream class.

The attribute stream must be defined in subclass.

read(number_of_bytes)[source]

Read n bytes from the current position and return a bytearray

seek(postion, whence=0)[source]

Seek to position.

tell()[source]

Tell the current position.

class PyDvi.Tools.Stream.FileStream(filename)[source]

Bases: PyDvi.Tools.Stream.StandardStream

class PyDvi.Tools.Stream.ByteStream(string_bytes)[source]

Bases: PyDvi.Tools.Stream.StandardStream

end_of_stream()
PyDvi.Tools.Stream.to_fix_word(x)[source]

Convert x to a fix word.

A fix word is a 32-bit representation of a binary fraction. A fix word is a signed quantity, with the two’s complement of the entire word used to represent negation. Of the 32 bits in a fix word, exactly 12 are to the left of the binary point; thus, the largest fix word value is 2048 - 2**-20, and the smallest is -2048.

fix word = x / 2**20

Previous topic

3.1.9.7. RevisionVersion

Next topic

3.1.9.9. TexCommentedFile

This Page