IDataSourceStream

class IDataSourceStream : public Stream

Base class for read-only stream.

Subclassed by FSTR::Stream, Graphics::SubStream, IFS::FWFS::ArchiveStream, MultiStream, ReadWriteStream, SectionStream, SharedMemoryStream< T >, StreamTransformer, TemplateStream, UrlencodedOutputStream, XorOutputStream

Public Functions

inline virtual StreamType getStreamType() const

Get the stream type.

Returns

StreamType – The stream type.

inline virtual bool isValid() const

Determine if the stream object contains valid data.

Note

Where inherited classes are initialised by constructor this method indicates whether that was successful or not (e.g. FileStream)

Returns

bool – true if valid, false if invalid

virtual size_t readBytes(char *buffer, size_t length) override

Read chars from stream into buffer.

Terminates if length characters have been read or timeout (see setTimeout). Returns the number of characters placed in the buffer (0 means no valid data found).

Note

Inherited classes may provide more efficient implementations without timeout.

virtual uint16_t readMemoryBlock(char *data, int bufSize) = 0

Read a block of memory.

Todo:

Should IDataSourceStream::readMemoryBlock return same data type as its bufSize param?

Parameters
  • data – Pointer to the data to be read

  • bufSize – Quantity of chars to read

Returns

uint16_t – Quantity of chars read

virtual int read() override

Read one character and moves the stream pointer.

Returns

The – character that was read or -1 if none is available

virtual int peek() override

Read a character without advancing the stream pointer.

Returns

int – The character that was read or -1 if none is available

inline virtual int seekFrom(int offset, SeekOrigin origin)

Change position in stream.

Note

This method is implemented by streams which support random seeking, such as files and memory streams.

Parameters
  • offset

  • origin

Returns

New – position, < 0 on error

inline virtual bool seek(int len)

Move read cursor.

Parameters

len – Relative cursor adjustment

Returns

bool – True on success.

virtual bool isFinished() = 0

Check if all data has been read.

Returns

bool – True on success.

inline virtual int available()

Return the total length of the stream.

Returns

int – -1 is returned when the size cannot be determined

inline virtual size_t write(uint8_t charToWrite) override

From Stream class: We don’t write using this stream.

Parameters

charToWrite

inline virtual String id() const

Returns unique id of the resource.

Returns

String – the unique id of the stream.

inline virtual String getName() const

Returns name of the resource.

Note

Commonly used to obtain name of file

Returns

String

inline virtual MimeType getMimeType() const

Get MIME type for stream content.

Returns

MimeType

virtual String readString(size_t maxLen) override

Overrides Stream method for more efficient reading.

Note

Stream position is updated by this call

inline virtual bool moveString(String &s)

Memory-based streams may be able to move content into a String.

If the operation is not supported by the stream, s will be invalidated and false returned.

Because a String object must have a NUL terminator, this will be appended if there is sufficient capacity. In this case, the method returns true.

If there is no capacity to add a NUL terminator, then the final character of stream data will be replaced with a NUL. The method returns false to indicate this.

Parameters

sString object to move data into

Returns

bool – true on success, false if there’s a problem.

enum SeekOrigin

Stream/file seek origins.

Values:

enumerator Start

SEEK_SET: Start of file.

enumerator Current

SEEK_CUR: Current position in file.

enumerator End

SEEK_END: End of file.