文档

OSS Connector中的数据类型

更新时间:

本文为您介绍OSS Connector for AI/ML中的数据类型。

数据类型

说明

DataObject仅支持只写模式或者只读模式,只读模式支持顺序读和随机读,只写模式仅支持顺序写。

DataObject作为OSS Connector for AI/ML中的数据类型,示例如下:

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: ...

属性方法

DataObject实现了常用的IO接口,具体请参见下表。

属性/方法

类型/返回值类型

描述

key

str

对象的唯一标识符。

size

int

对象的实际大小,单位为字节。

label

str

对象的标签,用于分类或标记。

__enter__

DataObject

进入上下文管理器的方法,返回DataObject实例本身。

__exit__

None

退出上下文管理器的方法,用于释放资源或执行清理操作。

tell

int

在只读模式下获取当前文件指针的位置,单位为字节。

seek

int

在只读模式下设置文件指针的位置,单位为字节。

read

bytes

在只读模式下从当前文件指针位置开始读取指定数量的字节,并以bytes类型返回。

readinto

int

在只读模式下从当前文件指针位置开始读取数据到缓冲区中,返回实际读取的字节数。

write

int

在只写模式下将数据写入当前文件指针位置,返回写入的字节数。

close

int

关闭文件,释放相关资源。

copy

DataObject

创建一个新的DataObject实例,包含当前实例的所有属性。