Stream
- class Stream
Stream
– abstraction for a source of bytes.Subclasses can be backed by memory, or a file, or something else.
NOTE:
Classic “streams” APIs are sort of async, in that on a request for N bytes, they may return fewer than N bytes on a given call, in which case the caller can “try again” to get more bytes, eventually (modulo an error) receiving their total N bytes.
Skia streams behave differently. They are effectively synchronous, and will always return all N bytes of the request if possible. If they return fewer (the read() call returns the number of bytes read) then that means there is no more data (at EOF or hit an error). The caller should not call again in hopes of fulfilling more of the request.
Subclasses
Methods
Attempts to open the specified file as a stream, returns nullptr on failure.
Duplicates this stream.
Duplicates this stream.
Returns the total length of the stream.
Returns the starting address for the data.
Returns the current position in the stream.
Returns true if this stream can report it's total length.
Returns true if this stream can report it's current position.
Returns true when all the bytes in the stream have been read.
Seeks to an relative offset in the stream.
Attempt to peek at size bytes.
Reads or skips size number of bytes.
Rewinds to the beginning of the stream.
Seeks to an absolute position in the stream.
Skip size number of bytes.
Methods
- static Stream.MakeFromFile(path: str) SkStreamAsset
Attempts to open the specified file as a stream, returns nullptr on failure.
- Stream.__init__(*args, **kwargs)
- Stream.duplicate(self: skia.Stream) skia.Stream
Duplicates this stream.
If this cannot be done, returns NULL. The returned stream will be positioned at the beginning of its data.
- Stream.fork(self: skia.Stream) skia.Stream
Duplicates this stream.
If this cannot be done, returns NULL. The returned stream will be positioned the same as this stream.
- Stream.getLength(self: skia.Stream) int
Returns the total length of the stream.
If this cannot be done, returns 0.
Reimplemented in
MemoryStream
,FILEStream
, andStreamAsset
.
- Stream.getMemoryBase(self: skia.Stream) capsule
Returns the starting address for the data.
If this cannot be done, returns NULL.
Reimplemented in
MemoryStream
, andStreamMemory
.
- Stream.getPosition(self: skia.Stream) int
Returns the current position in the stream.
If this cannot be done, returns 0.
Reimplemented in
MemoryStream
,FILEStream
, andStreamSeekable
.
- Stream.hasLength(self: skia.Stream) bool
Returns true if this stream can report it’s total length.
Reimplemented in
StreamAsset
.
- Stream.hasPosition(self: skia.Stream) bool
Returns true if this stream can report it’s current position.
Reimplemented in
StreamSeekable
.
- Stream.isAtEnd(self: skia.Stream) bool
Returns true when all the bytes in the stream have been read.
This may return true early (when there are no more bytes to be read) or late (after the first unsuccessful read).
Implemented in
MemoryStream
, andFILEStream
.
- Stream.move(self: skia.Stream, offset: int) bool
Seeks to an relative offset in the stream.
If this cannot be done, returns false. If an attempt is made to move to a position outside the stream, the position will be set to the closest point within the stream (beginning or end).
Reimplemented in
MemoryStream
,FILEStream
, andStreamSeekable
.
- Stream.peek(self: skia.Stream, buffer: Buffer) int
Attempt to peek at size bytes.
If this stream supports peeking, copy min(size, peekable bytes) into buffer, and return the number of bytes copied. If the stream does not support peeking, or cannot peek any bytes, return 0 and leave buffer unchanged. The stream is guaranteed to be in the same visible state after this call, regardless of success or failure.
- Parameters:
buffer – Must not be NULL, and must be at least size bytes. Destination to copy bytes.
size – Number of bytes to copy.
- Returns:
The number of bytes peeked/copied.
Reimplemented in
MemoryStream
.
- Stream.read(self: skia.Stream, buffer: Buffer, size: int = 0) int
Reads or skips size number of bytes.
If buffer == NULL, skip size bytes, return how many were skipped. If buffer != NULL, copy size bytes into buffer, return how many were copied.
- Parameters:
buffer – when NULL skip size bytes, otherwise copy size bytes into buffer
size – the number of bytes to skip or copy; may be nullptr
- Returns:
the number of bytes actually read.
Implemented in
MemoryStream
, andFILEStream
.
- Stream.readBool(self: skia.Stream) bool
- Stream.readPackedUInt(self: skia.Stream) int
- Stream.readS16(self: skia.Stream) int
- Stream.readS32(self: skia.Stream) int
- Stream.readS8(self: skia.Stream) int
- Stream.readScalar(self: skia.Stream) float
- Stream.readU16(self: skia.Stream) int
- Stream.readU32(self: skia.Stream) int
- Stream.readU8(self: skia.Stream) int
- Stream.rewind(self: skia.Stream) bool
Rewinds to the beginning of the stream.
Returns true if the stream is known to be at the beginning after this call returns.
Reimplemented in
MemoryStream
,FILEStream
, andStreamRewindable
.
- Stream.seek(self: skia.Stream, position: int) bool
Seeks to an absolute position in the stream.
If this cannot be done, returns false. If an attempt is made to seek past the end of the stream, the position will be set to the end of the stream.
Reimplemented in
MemoryStream
,FILEStream
, andStreamSeekable
.
- Stream.skip(self: skia.Stream, size: int) int
Skip size number of bytes.
- Returns:
the actual number bytes that could be skipped.