Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkStream Class Referenceabstract

SkStream – abstraction for a source of bytes. More...

#include <SkStream.h>

Inheritance diagram for SkStream:
SkStreamRewindable SkStreamSeekable SkStreamAsset SkFILEStream SkStreamMemory SkMemoryStream

Public Member Functions

virtual size_t read (void *buffer, size_t size)=0
 Reads or skips size number of bytes. More...
 
size_t skip (size_t size)
 Skip size number of bytes. More...
 
virtual size_t peek (void *, size_t) const
 Attempt to peek at size bytes. More...
 
virtual bool isAtEnd () const =0
 Returns true when all the bytes in the stream have been read. More...
 
int8_t readS8 ()
 
int16_t readS16 ()
 
int32_t readS32 ()
 
uint8_t readU8 ()
 
uint16_t readU16 ()
 
uint32_t readU32 ()
 
bool readBool ()
 
SkScalar readScalar ()
 
size_t readPackedUInt ()
 
virtual bool rewind ()
 Rewinds to the beginning of the stream. More...
 
virtual SkStreamRewindableduplicate () const
 Duplicates this stream. More...
 
virtual bool hasPosition () const
 Returns true if this stream can report it's current position. More...
 
virtual size_t getPosition () const
 Returns the current position in the stream. More...
 
virtual bool seek (size_t)
 Seeks to an absolute position in the stream. More...
 
virtual bool move (long)
 Seeks to an relative offset in the stream. More...
 
virtual SkStreamSeekablefork () const
 Duplicates this stream. More...
 
virtual bool hasLength () const
 Returns true if this stream can report it's total length. More...
 
virtual size_t getLength () const
 Returns the total length of the stream. More...
 
virtual const void * getMemoryBase ()
 Returns the starting address for the data. More...
 

Static Public Member Functions

static std::unique_ptr
< SkStreamAsset
MakeFromFile (const char path[])
 Attempts to open the specified file as a stream, returns nullptr on failure.
 

Detailed Description

SkStream – 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.

Member Function Documentation

virtual SkStreamRewindable* SkStream::duplicate ( ) const
inlinevirtual

Duplicates this stream.

If this cannot be done, returns NULL. The returned stream will be positioned at the beginning of its data.

Reimplemented in SkMemoryStream, SkFILEStream, SkStreamMemory, SkStreamAsset, SkStreamSeekable, and SkStreamRewindable.

virtual SkStreamSeekable* SkStream::fork ( ) const
inlinevirtual

Duplicates this stream.

If this cannot be done, returns NULL. The returned stream will be positioned the same as this stream.

Reimplemented in SkMemoryStream, SkFILEStream, SkStreamMemory, SkStreamAsset, and SkStreamSeekable.

virtual size_t SkStream::getLength ( ) const
inlinevirtual

Returns the total length of the stream.

If this cannot be done, returns 0.

Reimplemented in SkMemoryStream, SkFILEStream, and SkStreamAsset.

virtual const void* SkStream::getMemoryBase ( )
inlinevirtual

Returns the starting address for the data.

If this cannot be done, returns NULL.

Reimplemented in SkMemoryStream, and SkStreamMemory.

virtual size_t SkStream::getPosition ( ) const
inlinevirtual

Returns the current position in the stream.

If this cannot be done, returns 0.

Reimplemented in SkMemoryStream, SkFILEStream, and SkStreamSeekable.

virtual bool SkStream::hasLength ( ) const
inlinevirtual

Returns true if this stream can report it's total length.

Reimplemented in SkStreamAsset.

virtual bool SkStream::hasPosition ( ) const
inlinevirtual

Returns true if this stream can report it's current position.

Reimplemented in SkStreamSeekable.

virtual bool SkStream::isAtEnd ( ) const
pure virtual

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 SkMemoryStream, and SkFILEStream.

virtual bool SkStream::move ( long  )
inlinevirtual

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 SkMemoryStream, SkFILEStream, and SkStreamSeekable.

virtual size_t SkStream::peek ( void *  ,
size_t   
) const
inlinevirtual

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
bufferMust not be NULL, and must be at least size bytes. Destination to copy bytes.
sizeNumber of bytes to copy.
Returns
The number of bytes peeked/copied.

Reimplemented in SkMemoryStream.

virtual size_t SkStream::read ( void *  buffer,
size_t  size 
)
pure virtual

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
bufferwhen NULL skip size bytes, otherwise copy size bytes into buffer
sizethe number of bytes to skip or copy
Returns
the number of bytes actually read.

Implemented in SkMemoryStream, and SkFILEStream.

virtual bool SkStream::rewind ( )
inlinevirtual

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 SkMemoryStream, SkFILEStream, and SkStreamRewindable.

virtual bool SkStream::seek ( size_t  )
inlinevirtual

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 SkMemoryStream, SkFILEStream, and SkStreamSeekable.

size_t SkStream::skip ( size_t  size)
inline

Skip size number of bytes.

Returns
the actual number bytes that could be skipped.

The documentation for this class was generated from the following file: