IDataSourceStream

class IDataSourceStream : public Stream

Base class for read-only stream.

Subclassed by FSTR::Stream, IFS::FWFS::ArchiveStream, MultiStream, ReadWriteStream, SectionStream, StreamTransformer, TemplateStream, UrlencodedOutputStream

Public Functions

virtual StreamType getStreamType() const

Get the stream type.

Return Value
  • StreamType: The stream type.

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)

Return Value
  • bool: true if valid, false if invalid

size_t readBytes(char *buffer, size_t length)

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.

Parameters
  • data: Pointer to the data to be read

  • bufSize: Quantity of chars to read

Return Value
  • uint16_t: Quantity of chars read

int read()

Read one character and moves the stream pointer.

Return Value
  • The: character that was read or -1 if none is available

int peek()

Read a character without advancing the stream pointer.

Return Value
  • int: The character that was read or -1 if none is available

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:

Return Value
  • New: position, < 0 on error

virtual bool seek(int len)

Move read cursor.

Parameters
  • len: Relative cursor adjustment

Return Value
  • bool: True on success.

virtual bool isFinished() = 0

Check if all data has been read.

Return Value
  • bool: True on success.

virtual int available()

Return the total length of the stream.

Return Value
  • int: -1 is returned when the size cannot be determined

size_t write(uint8_t charToWrite)

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

Parameters
  • charToWrite:

int length()

Return the total length of the stream.

Return Value
  • int: -1 is returned when the size cannot be determined

virtual String id() const

Returns unique id of the resource.

Return Value
  • String: the unique id of the stream.

virtual String getName() const

Returns name of the resource.

Note

Commonly used to obtain name of file

Return Value

virtual MimeType getMimeType() const

Get MIME type for stream content.

Return Value
  • MimeType:

String readString(size_t maxLen)

Overrides Stream method for more efficient reading.

Note

Stream position is updated by this call

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.
Parameters
  • s: String object to move data into

Return Value
  • bool: true on success, false if there’s a problem.

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.

enum SeekOrigin

Stream/file seek origins.

Values:

Start = 0

SEEK_SET: Start of file.

Current = 1

SEEK_CUR: Current position in file.

End = 2

SEEK_END: End of file.