Data
- class Data
Data
holds an immutable data buffer.Not only is the data immutable, but the actual ptr that is returned (by
data()
orbytes()
) is guaranteed to always be the same for the life of this instance.Data
supports Python buffer protocol, meaning thatData
can be converted to Python buffer types without copy:bytes(data) memoryview(data) np.array(data)
Methods
MakeEmpty() -> skia.Data
MakeFromFileName(path: str) -> skia.Data
MakeSubset(src: skia.Data, offset: int, length: int) -> skia.Data
MakeUninitialized(length: int) -> skia.Data
MakeWithCopy(data: Buffer) -> skia.Data
MakeWithoutCopy(data: Buffer) -> skia.Data
__init__(self: skia.Data, buf: Buffer, copy: bool = False) -> None
bytes(self: skia.Data) -> bytes
copyRange(self: skia.Data, offset: int, length: int, buffer: object) -> int
data(self: skia.Data) -> memoryview
deref(self: skia.Data) -> None
equals(self: skia.Data, other: skia.Data) -> bool
isEmpty(self: skia.Data) -> bool
ref(self: skia.Data) -> None
refCntGreaterThan(self: skia.Data, count: int) -> bool
size(self: skia.Data) -> int
unique(self: skia.Data) -> bool
unref(self: skia.Data) -> None
writable_data(self: skia.Data) -> memoryview
Methods
- static Data.MakeEmpty() skia.Data
Returns a new empty dataref (or a reference to a shared empty dataref).
New or shared, the caller must see that unref() is eventually called.
- static Data.MakeFromFileName(path: str) skia.Data
Create a new dataref the file with the specified path.
If the file cannot be opened, this returns NULL.
- static Data.MakeSubset(src: skia.Data, offset: int, length: int) skia.Data
Create a new dataref using a subset of the data in the specified src dataref.
- static Data.MakeUninitialized(length: int) skia.Data
Create a new data with uninitialized contents.
The caller should call
writable_data()
to write into the buffer, but this must be done before anotherref()
is made.
- static Data.MakeWithCopy(data: Buffer) skia.Data
Create a new dataref by copying the specified data.
- static Data.MakeWithoutCopy(data: Buffer) skia.Data
Call this when the data parameter is already const and will outlive the lifetime of the
Data
.Suitable for with const globals.
- Data.__init__(self: skia.Data, buf: Buffer, copy: bool = False) None
Create a new
Data
.- Parameters:
buf (Union[bytes,bytearray,memoryview]) – Buffer object
copy (bool) – Whether to copy data, default False.
- Data.bytes(self: skia.Data) bytes
Like data(), returns a read-only ptr into the data, but in this case it is cast to
bytes
.
- Data.copyRange(self: skia.Data, offset: int, length: int, buffer: object) int
Helper to copy a range of the data into a caller-provided buffer.
Returns the actual number of bytes copied, after clamping offset and length to the size of the data. If buffer is NULL, it is ignored, and only the computed number of bytes is returned.