SpiffsParticleRK
Public Member Functions
SpiffsParticleFile Class Reference

Extension of Arduino/Wiring Stream/Print manipulating a single SPIFFS file. More...

#include <SpiffsParticleRK.h>

Inheritance diagram for SpiffsParticleFile:
Stream Print

Public Member Functions

 SpiffsParticleFile ()
 You normally don't need to instantiate one of these, you use the openFile method of SpiffsParticle instead.
 
 SpiffsParticleFile (spiffs_t *fs, spiffs_file fh)
 You normally don't need to instantiate one of these, you use the openFile method of SpiffsParticle instead.
 
virtual ~SpiffsParticleFile ()
 Destructor. Note that this only destroys the container, the underlying file handle is still open and valid.
 
 SpiffsParticleFile (const SpiffsParticleFile &other)
 You normally don't need to instantiate one of these, you use the openFile method of SpiffsParticle instead.
 
SpiffsParticleFileoperator= (const SpiffsParticleFile &other)
 You can copy this object, so it's safe to assign it to a local variable. More...
 
virtual int available ()
 Returns the number of bytes available to read from the current file position. More...
 
virtual int read ()
 Read a single byte from the current file position and increment the file position. More...
 
virtual int peek ()
 Read a single byte from the current file position, but do not increment the file position. More...
 
virtual void flush ()
 Write any buffered output. More...
 
virtual size_t readBytes (char *buffer, size_t length)
 Read a specified number of bytes from the file. More...
 
virtual size_t write (uint8_t c)
 Write a single byte to the current file position and increment the file position. More...
 
virtual size_t write (const uint8_t *buffer, size_t size)
 Write bytes to the current file position and increment the file position. More...
 
s32_t lseek (s32_t offs, int whence)
 Adjust the file position for reading or writing. More...
 
bool eof ()
 Returns true of the file position is currently at the end of the file. More...
 
s32_t tell ()
 Return the current file position from the start of the file. More...
 
s32_t length ()
 Returns the length of the file in bytes. More...
 
s32_t remove ()
 Delete the currently open file. More...
 
s32_t truncate (s32_t len)
 Truncate the currently open file to the specified number of bytes. More...
 
void seekStart ()
 Convenience function to move the file position to the beginning of the file.
 
void seekEnd ()
 Convenience function to move the file position to the end of the file.
 
void close ()
 Close this file. Make sure you close a file when done as there are a finite number of open file available.
 
bool isValid () const
 Returns true if this object appears to be valid. More...
 
 operator spiffs_file ()
 Get the underlying SPIFFS file handle for this file.
 
- Public Member Functions inherited from Stream
void setTimeout (system_tick_t timeout)
 Sets the read timeout (default: 1000 milliseconds) More...
 
bool find (char *target)
 Reads data from the stream until the target string is found. More...
 
bool find (char *target, size_t length)
 Reads data from the stream until the target string is found. More...
 
bool findUntil (char *target, char *terminator)
 Reads data from the stream until the target string is found or the terminator string is found. More...
 
bool findUntil (char *target, size_t targetLen, char *terminate, size_t termLen)
 Reads data from the stream until the target string is found or the terminator string is found. More...
 
long parseInt ()
 returns the first valid (long) integer value from the current position More...
 
float parseFloat ()
 returns the first valid float value from the current position More...
 
size_t readBytes (char *buffer, size_t length)
 Read chars from stream into buffer. More...
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 Read chars from stream into buffer until the character terminator is found. More...
 
String readString ()
 Reads the remainder of the file into a string.
 
String readStringUntil (char terminator)
 Reads the remainder of the file into a string or until terminator is found. More...
 
- Public Member Functions inherited from Print
int getWriteError ()
 Return the last error code. 0 means no error.
 
void clearWriteError ()
 Clear the last error code to 0.
 
size_t write (const char *str)
 Write a null-terminated c-string the stream or file. More...
 
size_t print (const char[])
 Print a null-terminated array of char variables (a c-string) to the stream or file.
 
size_t print (char)
 Print a single character to the stream or file.
 
size_t print (unsigned char value, int base=DEC)
 Print an unsigned char (byte value, 8 bits) in the specified base to the stream or file. More...
 
size_t print (int value, int base=DEC)
 Print an int (32 bit integer) the specified base to the stream or file. More...
 
size_t print (unsigned int value, int base=DEC)
 Print an unsigned int (32 bit unsigned integer) the specified base to the stream or file. More...
 
size_t print (long value, int base=DEC)
 Print a long (32 bit integer) the specified base to the stream or file. More...
 
size_t print (unsigned long value, int base=DEC)
 Print a unsigned long (32 bit unsigned integer) the specified base to the stream or file. More...
 
size_t print (double value, int dec=2)
 Print a double floating point value to the stream or file. More...
 
size_t print (const Printable &)
 Print an object derived from Printable to the stream or file.
 
size_t println (const char[])
 Print a null-terminated array of char variables (a c-string) plus a CRLF end-of-line terminator to the stream or file.
 
size_t println (char value)
 Print a single character plus a CRLF end-of-line terminator to the stream or file.
 
size_t println (unsigned char value, int base=DEC)
 Print an unsigned char (byte value. 8 bits) in the specified base plus a CRLF end-of-line terminator to the stream or file. More...
 
size_t println (int value, int base=DEC)
 Print an int (32 bit integer) the specified base to plus a CRLF end-of-line terminator the stream or file. More...
 
size_t println (unsigned int value, int base=DEC)
 Print an unsigned int (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More...
 
size_t println (long value, int base=DEC)
 Print a long (32 bit signed integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More...
 
size_t println (unsigned long value, int base=DEC)
 Print a unsigned long (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More...
 
size_t println (double value, int dec=2)
 Print a double floating point value plus a CRLF end-of-line terminator to the stream or file. More...
 
size_t println (const Printable &)
 Print an object derived from Printable plus a CRLF end-of-line terminator to the stream or file.
 
size_t println (void)
 Print a CRLF end-of-line terminator to the stream or file.
 
template<typename... Args>
size_t printf (const char *format, Args... args)
 Print using printf-style formatting to the stream or file. More...
 
template<typename... Args>
size_t printlnf (const char *format, Args... args)
 Print using printf-style formatting plus a CRLF end-of-line terminator to the stream or file. More...
 

Detailed Description

Extension of Arduino/Wiring Stream/Print manipulating a single SPIFFS file.

SpiffsParticleRK - Particle wrapper for SPIFFS library

Port and this wrapper: https://github.com/rickkas7/SpiffsParticleRK Original SPIFFS library: https://github.com/pellepl/spiffs/

License: MIT (both) You can use either this API, or the native SPIFFS API, which looks basically like the Unix file API.

Member Function Documentation

◆ available()

int SpiffsParticleFile::available ( )
virtual

Returns the number of bytes available to read from the current file position.

This is a standard Arduino/Wiring method for Stream objects.

Implements Stream.

◆ eof()

bool SpiffsParticleFile::eof ( )
inline

Returns true of the file position is currently at the end of the file.

Returns
true if at end of file, false if not

◆ flush()

void SpiffsParticleFile::flush ( )
virtual

Write any buffered output.

It is not necessary to flush before close, as close will automatically flush any output if necessary.

This is a standard Arduino/Wiring method for Stream objects.

Implements Stream.

◆ isValid()

bool SpiffsParticleFile::isValid ( ) const
inline

Returns true if this object appears to be valid.

This is mainly used when using the openFile method. Since this object is returned, you use the isValid() method to find out if the openFile succeeded. It might not if you try to open without create a file that does not exist, for example.

◆ length()

s32_t SpiffsParticleFile::length ( )

Returns the length of the file in bytes.

Returns
the length of the file in bytes or a negative error code

◆ lseek()

s32_t SpiffsParticleFile::lseek ( s32_t  offs,
int  whence 
)
inline

Adjust the file position for reading or writing.

Parameters
offsOffset, can be positive or negative
whenceOffset relative to what:
  • SPIFFS_SEEK_SET the beginning of the file
  • SPIFFS_SEEK_CUR the current file position
  • SPIFFS_SEEK_END the end of the file
Returns
SPIFFS_OK (0) on success, or a negative SPIFFS_ERR code.

This is a wrapper for the SPIFFS call, which emulates the Unix/POSIX API.

◆ operator=()

SpiffsParticleFile & SpiffsParticleFile::operator= ( const SpiffsParticleFile other)

You can copy this object, so it's safe to assign it to a local variable.

This object is only a container for the file handle; it doesn't do any reference counting and the file handle is only closed if you call the close() method; deleting this object or letting it go out of scope doesn't close the file handle.

◆ peek()

int SpiffsParticleFile::peek ( )
virtual

Read a single byte from the current file position, but do not increment the file position.

Returns
a byte value 0 - 255 or -1 if at the end of file.

This is a standard Arduino/Wiring method for Stream objects.

Implements Stream.

◆ read()

int SpiffsParticleFile::read ( )
virtual

Read a single byte from the current file position and increment the file position.

Returns
a byte value 0 - 255 or -1 if at the end of file.

This is a standard Arduino/Wiring method for Stream objects.

Implements Stream.

◆ readBytes()

size_t SpiffsParticleFile::readBytes ( char *  buffer,
size_t  length 
)
virtual

Read a specified number of bytes from the file.

Parameters
bufferThe buffer to write to
lengthThe number of bytes to read. It may read less than that.
Returns
The number of bytes read, which will be 0 to length bytes.

This is a standard Arduino/Wiring method for Stream objects.

◆ remove()

s32_t SpiffsParticleFile::remove ( )
inline

Delete the currently open file.

Note that the SpiffsParticle class has a method to delete a file by filename, this method is provided if you already have the file open.

Returns
SPIFFS_OK (0) on success, or a negative SPIFFS_ERR code.

◆ tell()

s32_t SpiffsParticleFile::tell ( )
inline

Return the current file position from the start of the file.

Returns
file position (0 = at the start of the file) or a negative error code

This is a wrapper for the SPIFFS call, which emulates the Unix/POSIX API.

◆ truncate()

s32_t SpiffsParticleFile::truncate ( s32_t  len)
inline

Truncate the currently open file to the specified number of bytes.

Note that in POSIX, you can truncate a file to make it longer than the current file length but in SPIFFS you can only truncate a file to be equal to or less than the current file length.

Returns
SPIFFS_OK (0) on success, or a negative SPIFFS_ERR code.

◆ write() [1/2]

size_t SpiffsParticleFile::write ( uint8_t  c)
virtual

Write a single byte to the current file position and increment the file position.

Parameters
cThe byte to write. Can write binary or text data.

This is a standard Arduino/Wiring method for Stream objects.

Implements Print.

◆ write() [2/2]

size_t SpiffsParticleFile::write ( const uint8_t *  buffer,
size_t  size 
)
virtual

Write bytes to the current file position and increment the file position.

Parameters
bufferThe buffer to write. Can write binary or text data.
lengthThe number of bytes to write.
Returns
The number of bytes written, typically this will be length.

This is a standard Arduino/Wiring method for Stream objects.

Reimplemented from Print.


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