All Products
Search
Document Center

Object Storage Service:Data type in OSS Connector

Last Updated:Sep 18, 2024

This topic describes the data type in OSS Connector for AI/ML.

Data type

Note

The DataObject data type in OSS Connector for AI/ML supports only the write-only or the read-only mode. The read-only mode supports sequential read and random read. The write-only mode supports only sequential write.

Example:

class DataObject:
    key: str
    size: int
    label: str

    def __enter__(self) -> DataObject: ...   
    def __exit__(self, exc_type, exc_val, exc_tb): ...
    def tell(self) -> int: ...
    def seek(self, offset: int, whence: int) -> int: ...
    def read(self, count: int) -> bytes: ...
    def readinto(self, buf) -> int: ...
    def write(self, data) -> int: ...
    def close(self) -> int: ...
    def copy(self) -> DataObject: ...

Methods

DataObject supports common I/O methods. The following table describes the I/O methods.

Method

Type/Return value type

Description

key

str

The unique identifier of the object.

size

int

The actual size of the object. Unit: bytes.

label

str

The tags of the object, which are used for classification or labeling.

__enter__

DataObject

The method that is used to go to the context manager to initialize the DataObject instance.

__exit__

None

The method that is used to exit the context manager to release resources or perform cleanup operations.

tell

int

Obtains the position of the current file pointer in read-only mode. Unit: bytes.

seek

int

Specifies the position of the file pointer in read-only mode. Unit: bytes.

read

bytes

Reads the specified number of bytes starting from the position of the current file pointer in read-only mode. Unit: bytes.

readinto

int

Reads data starting from the position of the current file pointer to the buffer in read-only mode, and returns the actual number of bytes that are read.

write

int

Writes data to the position of the current file pointer in write-only mode and returns the number of bytes that are written.

close

int

Closes the file and releases the related resources.

copy

DataObject

Creates a new DataObject instance that contains all attributes of the current instance.