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
Returns a new empty dataref (or a reference to a shared empty dataref).
Create a new dataref the file with the specified path.
Create a new dataref using a subset of the data in the specified src dataref.
Create a new data with uninitialized contents.
Create a new dataref by copying the specified data.
Call this when the data parameter is already const and will outlive the lifetime of the
Data
.Create a new
Data
.Like data(), returns a read-only ptr into the data, but in this case it is cast to
bytes
.Helper to copy a range of the data into a caller-provided buffer.
Returns the read-only memoryview to the data.
Returns true if these two objects have the same length and contents, effectively returning 0 == memcmp(...)
Returns the number of bytes stored.
USE WITH CAUTION.
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.