FileHelperRK
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes
FileHelperRK::FileStreamRead Class Reference

Class for reading from a file as a Stream. More...

#include <FileHelperRK.h>

Inheritance diagram for FileHelperRK::FileStreamRead:
FileHelperRK::FileStreamBase

Public Member Functions

int open (const char *path)
 Open a file for reading. Opens as O_RDONLY.
 
int rewind ()
 Start reading from the beginning of the file again.
 
virtual int available ()
 Returns number of bytes available to read. Override for Stream pure virtual function.
 
virtual int read ()
 Read a byte from the file. Override for Stream pure virtual function.
 
virtual int peek ()
 Read a byte from the file without consuming it. Override for Stream pure virtual function.
 
virtual void flush ()
 Doesn't do anything. Override for Stream pure virtual function.
 
virtual size_t write (uint8_t)
 Doesn't do anything. Override for Stream::Print pure virtual function.
 
void updateFileSize ()
 Updates the fileSize parameter. Called from open().
 
- Public Member Functions inherited from FileHelperRK::FileStreamBase
 FileStreamBase ()
 Construct object; you will typically do this and then call openForReading or openForWriting.
 
 FileStreamBase (int fd)
 Construct object from an existing file descriptor from open()
 
virtual ~FileStreamBase ()
 Destructor.
 
int open (const char *path, int mode, int perm=0666)
 Open a file.
 
int close ()
 Close the underling file if it was opened using open()
 

Protected Attributes

size_t fileSize = 0
 File size in bytes, set in open() and updateFileSize().
 
size_t fileOffset = 0
 File position, set in open() and rewind(), updated on read()
 
- Protected Attributes inherited from FileHelperRK::FileStreamBase
int fd = -1
 File descriptor from open()
 
bool closeFile = false
 Close file on destructor.
 

Detailed Description

Class for reading from a file as a Stream.

Used for reading a Variant from a file as CBOR.

Member Function Documentation

◆ available()

int FileHelperRK::FileStreamRead::available ( )
virtual

Returns number of bytes available to read. Override for Stream pure virtual function.

Returns
int Number of bytes to read or 0 at end of file

◆ open()

int FileHelperRK::FileStreamRead::open ( const char * path)

Open a file for reading. Opens as O_RDONLY.

Parameters
pathFilename to read from.
Returns
int SYSTEM_ERROR_NONE (0) on success or a system error code (non-zero)

◆ peek()

int FileHelperRK::FileStreamRead::peek ( )
virtual

Read a byte from the file without consuming it. Override for Stream pure virtual function.

Returns
int A value from 0 - 255 inclusive or -1 on error.

◆ read()

int FileHelperRK::FileStreamRead::read ( )
virtual

Read a byte from the file. Override for Stream pure virtual function.

Returns
int A value from 0 - 255 inclusive or -1 on error.

◆ rewind()

int FileHelperRK::FileStreamRead::rewind ( )

Start reading from the beginning of the file again.

Returns
int SYSTEM_ERROR_NONE (0) on success or a system error code (non-zero)

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