Skia
2D Graphics Library
SkFILEStream Class Reference

A stream that wraps a C FILE* file stream. More...

#include <SkStream.h>

Inheritance diagram for SkFILEStream:

Public Member Functions

 SkFILEStream (const char path[]=nullptr)
 Initialize the stream by calling sk_fopen on the specified path. More...
 
 SkFILEStream (FILE *file)
 Initialize the stream with an existing C FILE stream. More...
 
 SkFILEStream (FILE *file, size_t size)
 Initialize the stream with an existing C FILE stream. More...
 
 ~SkFILEStream () override
 
bool isValid () const
 Returns true if the current path could be opened. More...
 
void close ()
 Close this SkFILEStream. More...
 
size_t read (void *buffer, size_t size) override
 Reads or skips size number of bytes. More...
 
bool isAtEnd () const override
 Returns true when all the bytes in the stream have been read. More...
 
bool rewind () override
 Rewinds to the beginning of the stream. More...
 
std::unique_ptr< SkStreamAssetduplicate () const
 
size_t getPosition () const override
 Returns the current position in the stream. More...
 
bool seek (size_t position) override
 Seeks to an absolute position in the stream. More...
 
bool move (long offset) override
 Seeks to an relative offset in the stream. More...
 
std::unique_ptr< SkStreamAssetfork () const
 
size_t getLength () const override
 Returns the total length of the stream. More...
 
bool hasLength () const override
 Returns true if this stream can report its total length. More...
 
bool hasPosition () const override
 Returns true if this stream can report its current position. 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...
 
bool readS8 (int8_t *)
 
bool readS16 (int16_t *)
 
bool readS32 (int32_t *)
 
bool readU8 (uint8_t *i)
 
bool readU16 (uint16_t *i)
 
bool readU32 (uint32_t *i)
 
bool readBool (bool *b)
 
bool readScalar (SkScalar *)
 
bool readPackedUInt (size_t *)
 
virtual const void * getMemoryBase ()
 Returns the starting address for the data. More...
 

Static Public Member Functions

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

Detailed Description

A stream that wraps a C FILE* file stream.

Constructor & Destructor Documentation

◆ SkFILEStream() [1/3]

SkFILEStream::SkFILEStream ( const char  path[] = nullptr)
explicit

Initialize the stream by calling sk_fopen on the specified path.

This internal stream will be closed in the destructor.

◆ SkFILEStream() [2/3]

SkFILEStream::SkFILEStream ( FILE *  file)
explicit

Initialize the stream with an existing C FILE stream.

The current position of the C FILE stream will be considered the beginning of the SkFILEStream and the current seek end of the FILE will be the end. The C FILE stream will be closed in the destructor.

◆ SkFILEStream() [3/3]

SkFILEStream::SkFILEStream ( FILE *  file,
size_t  size 
)
explicit

Initialize the stream with an existing C FILE stream.

The current position of the C FILE stream will be considered the beginning of the SkFILEStream and size bytes later will be the end. The C FILE stream will be closed in the destructor.

◆ ~SkFILEStream()

SkFILEStream::~SkFILEStream ( )
override

Member Function Documentation

◆ close()

void SkFILEStream::close ( )

Close this SkFILEStream.

◆ duplicate()

std::unique_ptr<SkStreamAsset> SkFILEStream::duplicate ( ) const
inline

◆ fork()

std::unique_ptr<SkStreamAsset> SkFILEStream::fork ( ) const
inline

◆ getLength()

size_t SkFILEStream::getLength ( ) const
overridevirtual

Returns the total length of the stream.

If this cannot be done, returns 0.

Implements SkStreamAsset.

◆ getMemoryBase()

virtual const void* SkStream::getMemoryBase ( )
inlinevirtualinherited

Returns the starting address for the data.

If this cannot be done, returns NULL.

Reimplemented in SkStreamMemory, and SkMemoryStream.

◆ getPosition()

size_t SkFILEStream::getPosition ( ) const
overridevirtual

Returns the current position in the stream.

If this cannot be done, returns 0.

Implements SkStreamSeekable.

◆ hasLength()

bool SkStreamAsset::hasLength ( ) const
inlineoverridevirtualinherited

Returns true if this stream can report its total length.

Reimplemented from SkStream.

◆ hasPosition()

bool SkStreamSeekable::hasPosition ( ) const
inlineoverridevirtualinherited

Returns true if this stream can report its current position.

Reimplemented from SkStream.

◆ isAtEnd()

bool SkFILEStream::isAtEnd ( ) const
overridevirtual

Returns true when all the bytes in the stream have been read.

As SkStream represents synchronous I/O, isAtEnd returns false when the final stream length isn't known yet, even when all the bytes available so far have been read. This may return true early (when there are no more bytes to be read) or late (after the first unsuccessful read).

Implements SkStream.

◆ isValid()

bool SkFILEStream::isValid ( ) const
inline

Returns true if the current path could be opened.

◆ Make()

static std::unique_ptr<SkFILEStream> SkFILEStream::Make ( const char  path[])
inlinestatic

◆ MakeFromFile()

static std::unique_ptr<SkStreamAsset> SkStream::MakeFromFile ( const char  path[])
staticinherited

Attempts to open the specified file as a stream, returns nullptr on failure.

◆ move()

bool SkFILEStream::move ( long  )
overridevirtual

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

Implements SkStreamSeekable.

◆ peek()

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

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.

◆ read()

size_t SkFILEStream::read ( void *  buffer,
size_t  size 
)
overridevirtual

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.

Implements SkStream.

◆ readBool()

bool SkStream::readBool ( bool *  b)
inlineinherited

◆ readPackedUInt()

bool SkStream::readPackedUInt ( size_t *  )
inherited

◆ readS16()

bool SkStream::readS16 ( int16_t *  )
inherited

◆ readS32()

bool SkStream::readS32 ( int32_t *  )
inherited

◆ readS8()

bool SkStream::readS8 ( int8_t *  )
inherited

◆ readScalar()

bool SkStream::readScalar ( SkScalar )
inherited

◆ readU16()

bool SkStream::readU16 ( uint16_t *  i)
inlineinherited

◆ readU32()

bool SkStream::readU32 ( uint32_t *  i)
inlineinherited

◆ readU8()

bool SkStream::readU8 ( uint8_t *  i)
inlineinherited

◆ rewind()

bool SkFILEStream::rewind ( )
overridevirtual

Rewinds to the beginning of the stream.

Returns true if the stream is known to be at the beginning after this call returns.

Implements SkStreamRewindable.

◆ seek()

bool SkFILEStream::seek ( size_t  )
overridevirtual

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.

Implements SkStreamSeekable.

◆ skip()

size_t SkStream::skip ( size_t  size)
inlineinherited

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: