IDataSourceStream
-
class IDataSourceStream : public Stream
Base class for read-only stream.
Subclassed by FSTR::Stream, Graphics::SubStream, IFS::FWFS::ArchiveStream, MultiStream, ReadWriteStream, RtttlJsonListStream, SectionStream, SharedMemoryStream< T >, StreamTransformer, TemplateStream, UPnP::DescriptionStream, UrlencodedOutputStream, XorOutputStream
Public Functions
-
inline virtual StreamType getStreamType() const
Get the stream type.
- Return values:
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)
- Return values:
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
- Return values:
uint16_t – Quantity of chars read
-
virtual int read() override
Read one character and moves the stream pointer.
- Return values:
The – character that was read or -1 if none is available
-
virtual int peek() override
Read a character without advancing the stream pointer.
- Return values:
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 –
- Return values:
New – position, < 0 on error
-
inline virtual bool seek(int len)
Move read cursor.
- Parameters:
len – Relative cursor adjustment
- Return values:
bool – True on success.
-
virtual bool isFinished() = 0
Check if all data has been read.
- Return values:
bool – True on success.
-
inline virtual int available()
Return the total length of the stream.
- Return values:
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.
- Return values:
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
- Return values:
String –
-
inline virtual MimeType getMimeType() const
Get MIME type for stream content.
- Return values:
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:
s – String object to move data into
- Return values:
bool – true on success, false if there’s a problem.
-
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.
-
inline virtual StreamType getStreamType() const