Data

class Data

Data holds an immutable data buffer.

Not only is the data immutable, but the actual ptr that is returned (by data() or bytes()) is guaranteed to always be the same for the life of this instance.

Data supports Python buffer protocol, meaning that Data can be converted to Python buffer types without copy:

bytes(data)
memoryview(data)
np.array(data)

Methods

MakeEmpty

Returns a new empty dataref (or a reference to a shared empty dataref).

MakeFromFileName

Create a new dataref the file with the specified path.

MakeSubset

Create a new dataref using a subset of the data in the specified src dataref.

MakeUninitialized

Create a new data with uninitialized contents.

MakeWithCopy

Create a new dataref by copying the specified data.

MakeWithoutCopy

Call this when the data parameter is already const and will outlive the lifetime of the Data.

__init__

__init__(self: skia.Data, buf: buffer, copy: bool = False) -> None

bytes

Like data(), returns a read-only ptr into the data, but in this case it is cast to bytes.

copyRange

Helper to copy a range of the data into a caller-provided buffer.

data

Returns the read-only memoryview to the data.

deref

equals

Returns true if these two objects have the same length and contents, effectively returning 0 == memcmp(…)

isEmpty

ref

refCntGreaterThan

size

Returns the number of bytes stored.

unique

unref

writable_data

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 another ref() 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

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

Data.data(self: skia.Data) memoryview

Returns the read-only memoryview to the data.

Data.deref(self: skia.Data) None
Data.equals(self: skia.Data, other: skia.Data) bool

Returns true if these two objects have the same length and contents, effectively returning 0 == memcmp(…)

Data.isEmpty(self: skia.Data) bool
Data.ref(self: skia.Data) None
Data.refCntGreaterThan(self: skia.Data, count: int) bool
Data.size(self: skia.Data) int

Returns the number of bytes stored.

Data.unique(self: skia.Data) bool
Data.unref(self: skia.Data) None
Data.writable_data(self: skia.Data) memoryview

USE WITH CAUTION.

Returns the read-write memoryview to the data.

This call will assert that the refcnt is 1, as a precaution against modifying the contents when another client/thread has access to the data.