Utils

class utils.FilePtr(fp, total_length=None, offset=0)

A wrapper for file object to maintain some more states during parsing.

  • In file mode, total_length can be left None and will be read from file system.
  • In streaming mode, you must provide total_length to specify the end of the stream.
Parameters:
  • fp – Original file object.
  • total_length – Length of this.
  • offset – Offset to the original file.
close()

Set internal references to None.

Note that it will not close the original file object.

static get_file_length(fp)

Get length of the file from local file system.

read(n)

Read bytes.

Parameters:n – Count of bytes to read.
Returns:Bytes.
restore_state()

Restore last internal state.

save_state()

Save internal state.

seek(pos, mode=0)

Seek position in sub file.

Parameters:
  • pos – Position.
  • mode – Seek mode.
tell()

Current position in sub file.

Returns:Current position.

Previous topic

Fields

This Page