aistore.sdk.obj.obj_file.object_file
aistore.sdk.obj.obj_file.object_file
Module Contents
Classes
Data
API
Bases: BufferedIOBase
A sequential read-only file-like object extending BufferedIOBase for reading object data, with support for both
reading a fixed size of data and reading until the end of file (EOF).
When a read is requested, any remaining data from a previously fetched chunk is returned first. If the remaining
data is insufficient to satisfy the request, the read() method fetches additional chunks from the provided
iterator as needed, until the requested size is fulfilled or the end of the stream is reached.
In case of unexpected stream interruptions (e.g. ChunkedEncodingError, ConnectionError) or timeouts (e.g.
ReadTimeout), the read() method automatically retries and resumes fetching data from the last successfully
retrieved chunk. The max_resume parameter controls how many retry attempts are made before an error is raised.
Parameters:
A provider that creates iterators which can fetch object data from AIS in chunks.
Maximum number of resumes allowed for an ObjectFileReader instance.
Handle the broken stream/iterator by incrementing the resume count, logging a warning, and returning a newly instantiated iterator from the last known position.
Parameters:
The error that caused the resume attempt.
Returns: Optional[Generator[bytes, None, None]]
Optional[Generator[bytes, None, None]]: The new generator. None if the object is not cached.
Raises:
ObjectFileReaderMaxResumeError: If the maximum number of resume attempts is exceeded.
Close the file.
Read up to ‘size’ bytes from the object. If size is -1, read until the end of the stream.
Parameters:
The number of bytes to read. If -1, reads until EOF.
Returns: bytes
The read data as a bytes object.
Raises:
ObjectFileReaderStreamError: If a connection cannot be made.ObjectFileReaderMaxResumeError: If the stream is interrupted more than the allowed maximum.ValueError: I/O operation on a closed file.Exception: Any other errors while streaming and reading.
Return whether the file is readable.
Bases: BufferedWriter
A file-like writer object for AIStore, extending BufferedWriter.
Parameters:
The ObjectWriter instance for handling write operations.
Specifies the mode in which the file is opened.
'w': Write mode. Opens the object for writing, truncating any existing content. Writing starts from the beginning of the object.'a': Append mode. Opens the object for appending. Existing content is preserved, and writing starts from the end of the object.
Close the writer and finalize the object.
Flush the writer, ensuring the object is finalized.
This does not close the writer but makes the current state accessible.
Raises:
ValueError: I/O operation on a closed file.
Write data to the object.
Parameters:
The data to write.
Returns: int
Number of bytes written.
Raises:
ValueError: I/O operation on a closed file.