s3torchconnector.s3reader
Classes
A read-only, file like representation of a single object stored in S3. |
Module Contents
- class s3torchconnector.s3reader.S3Reader(bucket: str, key: str, get_object_info: Callable[[], s3torchconnectorclient._mountpoint_s3_client.ObjectInfo | s3torchconnectorclient._mountpoint_s3_client.HeadObjectResult], get_stream: Callable[[], s3torchconnectorclient._mountpoint_s3_client.GetObjectStream])[source]
Bases:
io.BufferedIOBase
A read-only, file like representation of a single object stored in S3.
- prefetch() None [source]
Start fetching data from S3.
- Raises:
S3Exception – An error occurred accessing S3.
- readinto(buf) int [source]
Read up to len(buf) bytes into a pre-allocated, writable bytes-like object buf. Return the number of bytes read. If no bytes are available, zero is returned.
- Parameters:
buf – writable bytes-like object
- Returns:
numer of bytes read or zero, if no bytes available
- Return type:
int
- read(size: int | None = None) bytes [source]
Read up to size bytes from the object and return them.
If size is zero or positive, read that many bytes from S3, or until the end of the object. If size is None or negative, read the entire file.
- Parameters:
size (int | None) – how many bytes to read.
- Returns:
Bytes read from S3 Object
- Return type:
bytes
- Raises:
S3Exception – An error occurred accessing S3.
- seek(offset: int, whence: int = SEEK_SET, /) int [source]
Change the stream position to the given byte offset, interpreted relative to whence.
When seeking beyond the end of the file, always stay at EOF. Seeking before the start of the file results in a ValueError.
- Parameters:
offset (int) – How many bytes to seek relative to whence.
whence (int) – One of SEEK_SET, SEEK_CUR, and SEEK_END. Default: SEEK_SET
- Returns:
Current position of the stream
- Return type:
int
- Raises:
S3Exception – An error occurred accessing S3.