Torch Object Storage
Parameter | Item | Default value | Description |
Parameter | Item | Default value | Description |
region | str | Yes | Region where the target Bucket is located, for example, 'cn-beijing'. |
endpoint | str | '' | TOS external access domain name. If empty, the default Endpoint will be used based on region; specify explicitly here for intranet access or custom domain. |
key | str | '' | Access Key ID for accessing TOS. Explicit configuration is recommended. |
secret | str | '' | Secret Access Key for accessing TOS. |
part_size | int | 8 * 1024 * 1024 | Base part size (bytes) for multipart upload and multipart copy. tip part_size must be greater than or equal to 4 * 1024 * 1024, or a ValueError will be raised. |
max_retry_count | int | 3 | Maximum number of retries for a failed request. |
shared_prefetch_tasks | int | 32 | Number of concurrent prefetch tasks during read. |
shared_upload_part_tasks | int | 32 | Number of concurrent tasks during multipart upload. |
shared_upload_part_copy_tasks | int | 32 | Number of concurrent tasks during multipart copy. |
enable_crc | bool | True | Enable CRC64 checksum. Enabled for data integrity verification after upload and download. |
Method/Attribute | Description |
Method/Attribute | Description |
read(size=-1) | Read the specified number of bytes from the current position. size=-1 means read until the end of the file. |
readinto(buf) | Read data directly into the writable buffer object buf and return the actual number of bytes read, avoiding extra memory copying. |
readuntil(char=b'\n', blocks=None) | Continuously read data until the specified delimiter char (including the delimiter) or the end of the file is reached. |
write(data) | Write the byte data data into the file buffer. |
seek(loc, whence=0) | Move the file pointer to the specified position. whence can be 0 (beginning), 1 (current position), or 2 (end of file). |
tell() | Return the current position of the file pointer. |
flush(force=False) | Flushes the accumulated data in the buffer to the underlying write stream. Usually called automatically by commit() or when closing the file. |
commit() | Commits all data in the current buffer. Explicit calls are generally unnecessary for write modes with auto-commit enabled. |
discard() | Abandons the current write session, terminates the underlying shard upload, and discards uncommitted data. |
close() | Closes the file and ensures all data is written. Automatically called when exiting the with statement block. |
readable() / writable() / seekable() | Return boolean values indicating whether the file supports reading, writing, or random access. |
closed | Indicates whether the file is closed. |
bucket | Name of the bucket to which the current file belongs. |
key | Object key of the current file within the bucket. |