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

MakeEmpty() -> skia.Data

MakeFromFileName

MakeFromFileName(path: str) -> skia.Data

MakeSubset

MakeSubset(src: skia.Data, offset: int, length: int) -> skia.Data

MakeUninitialized

MakeUninitialized(length: int) -> skia.Data

MakeWithCopy

MakeWithCopy(data: Buffer) -> skia.Data

MakeWithoutCopy

MakeWithoutCopy(data: Buffer) -> skia.Data

__init__

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

bytes

bytes(self: skia.Data) -> bytes

copyRange

copyRange(self: skia.Data, offset: int, length: int, buffer: object) -> int

data

data(self: skia.Data) -> memoryview

deref

deref(self: skia.Data) -> None

equals

equals(self: skia.Data, other: skia.Data) -> bool

isEmpty

isEmpty(self: skia.Data) -> bool

ref

ref(self: skia.Data) -> None

refCntGreaterThan

refCntGreaterThan(self: skia.Data, count: int) -> bool

size

size(self: skia.Data) -> int

unique

unique(self: skia.Data) -> bool

unref

unref(self: skia.Data) -> None

writable_data

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

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.