Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 2.16 KB

stream.md

File metadata and controls

60 lines (44 loc) · 2.16 KB

Streams

Input and output streams are exposed by DataStore instances via open_read and open_write functions. They allow data to be read from or written to a data store in binary form. Depending on the data store a stream can be seekable and can support zero-copy reading/writing.

InputStream

Reads data from an underlying DataStore instance. An InputStream instance is usually retrieved by calling the open_read method of a data store.

Methods

read

Expects the caller to provide a writable Python object that supports the Python Buffer protocol (e.g. array.array). It fills the specified buffer with data read from the underlying data store and returns the number of bytes read.

read(buf : Buffer)
  • buf: A writable Python object that supports the Python Buffer protocol

seek

Seeks to the specified position in the stream.

seek(pos : int)
  • pos: The new position in the stream

close

Closes the input stream.

close()

__enter__ and __exit__

InputStream supports the context manager protocol and can be automatically closed via a with statement.

Properties

size

Gets the size of the stream. Only supported by seekable streams; otherwise, raises a NotSupportedError.

seekable

Gets a boolean value indicating whether the stream is seekable.

supports_zero_copy

Gets a boolean value indicating whether the stream supports zero-copy reading.

closed

Gets a boolean value indicating whether the stream is closed.

OutputStream

Not implemented yet

Exceptions

Type Description
StreamError Thrown when the stream cannot be read. Inherits from MLIOError.
InflateError Thrown when the stream cannot be decompressed. Inherits from StreamError.