Wraps up all file access methods. More...

#include <File.h>

Inheritance diagram for IFS::File:
[legend]
Collaboration diagram for IFS::File:
[legend]

Public Types

using ReadContentCallback = FileSystem::ReadContentCallback
 

Public Member Functions

 ~File ()
 
 operator bool () const
 
bool stat (Stat &stat)
 get file information More...
 
int control (ControlCode code, void *buffer, size_t bufSize)
 Low-level and non-standard file control operations. More...
 
template<typename T >
bool open (const T &path, OpenFlags flags=OpenFlag::Read)
 open a file by name/path More...
 
bool close ()
 close an open file More...
 
int read (void *data, size_t size)
 read content from a file and advance cursor More...
 
int write (const void *data, size_t size)
 write content to a file at current position and advance cursor More...
 
bool write (const String &s)
 
int seek (int offset, SeekOrigin origin)
 change file read/write position More...
 
bool eof ()
 determine if current file position is at end of file More...
 
int32_t tell ()
 get current file position More...
 
bool truncate (size_t new_size)
 Truncate (reduce) the size of an open file. More...
 
bool truncate ()
 Truncate an open file at the current cursor position. More...
 
bool flush ()
 flush any buffered data to physical media More...
 
bool setacl (const ACL &acl)
 Set access control information for file. More...
 
bool settime (time_t mtime)
 Set modification time for file. More...
 
bool setcompression (const Compression &compression)
 Set file compression information. More...
 
template<typename... ParamTypes>
bool setAttribute (AttributeTag tag, ParamTypes... params)
 
template<typename... ParamTypes>
int getAttribute (AttributeTag tag, ParamTypes... params)
 
template<typename... ParamTypes>
bool setUserAttribute (uint8_t tagValue, ParamTypes... params)
 
template<typename... ParamTypes>
int getUserAttribute (uint8_t tagValue, ParamTypes... params)
 
String getUserAttribute (uint8_t tagValue)
 
bool removeUserAttribute (uint8_t tagValue)
 
int enumAttributes (AttributeEnumCallback callback, void *buffer, size_t bufsize)
 
bool remove ()
 remove (delete) an open file (and close it) More...
 
uint32_t getSize ()
 Get size of file. More...
 
int readContent (size_t size, ReadContentCallback callback)
 Read from current file position and invoke callback for each block read. More...
 
int readContent (ReadContentCallback callback)
 Read from current file position to end of file and invoke callback for each block read. More...
 
String getContent ()
 Read content of a file. More...
 
- Public Member Functions inherited from IFS::FsBase
 FsBase (IFileSystem *filesys)
 
bool isValid () const
 
int getLastError ()
 determine if an error occurred during operation More...
 
String getErrorString (int err) const
 
String getLastErrorString () const
 
FileSystemgetFileSystem () const
 

Static Public Attributes

static constexpr OpenFlags ReadOnly {OpenFlag::Read}
 
static constexpr OpenFlags WriteOnly {OpenFlag::Write}
 
static constexpr OpenFlags ReadWrite {OpenFlag::Read | OpenFlag::Write}
 
static constexpr OpenFlags Create {OpenFlag::Create}
 
static constexpr OpenFlags Append {OpenFlag::Append}
 
static constexpr OpenFlags Truncate {OpenFlag::Truncate}
 
static constexpr OpenFlags CreateNewAlways {OpenFlag::Create | OpenFlag::Truncate}
 

Additional Inherited Members

- Protected Member Functions inherited from IFS::FsBase
bool check (int res)
 Check file operation result and note error code. More...
 
- Protected Attributes inherited from IFS::FsBase
int lastError {FS_OK}
 

Detailed Description

Wraps up all file access methods.

Member Typedef Documentation

◆ ReadContentCallback

Constructor & Destructor Documentation

◆ ~File()

IFS::File::~File ( )
inline

Member Function Documentation

◆ close()

bool IFS::File::close ( )
inline

close an open file

Return values
booltrue on success

◆ control()

int IFS::File::control ( ControlCode  code,
void *  buffer,
size_t  bufSize 
)
inline

Low-level and non-standard file control operations.

Parameters
codeFCNTL_XXX code
bufferInput/Output buffer
bufSizeSize of buffer
Return values
interror code or, on success, data size

To simplify usage the same buffer is used for both input and output. Only the size of the buffer is provided. If a specific FCNTL code requires more information then it will be contained within the provided data.

◆ enumAttributes()

int IFS::File::enumAttributes ( AttributeEnumCallback  callback,
void *  buffer,
size_t  bufsize 
)
inline

◆ eof()

bool IFS::File::eof ( )
inline

determine if current file position is at end of file

Return values
booltrue if at EOF or file is invalid

◆ flush()

bool IFS::File::flush ( )
inline

flush any buffered data to physical media

Return values
booltrue on success

◆ getAttribute()

template<typename... ParamTypes>
int IFS::File::getAttribute ( AttributeTag  tag,
ParamTypes...  params 
)
inline

◆ getContent()

String IFS::File::getContent ( )
inline

Read content of a file.

Parameters
fileNameName of file to read from
Return values
StringString variable in to which to read the file content
Note
After calling this function the content of the file is placed in to a string. The result will be an invalid String (equates to false) if the file could not be read. If the file exists, but is empty, the result will be an empty string "".

◆ getSize()

uint32_t IFS::File::getSize ( )
inline

Get size of file.

Return values
uint32_tSize of file in bytes, 0 on error

◆ getUserAttribute() [1/2]

template<typename... ParamTypes>
int IFS::File::getUserAttribute ( uint8_t  tagValue,
ParamTypes...  params 
)
inline

◆ getUserAttribute() [2/2]

String IFS::File::getUserAttribute ( uint8_t  tagValue)
inline

◆ open()

template<typename T >
bool IFS::File::open ( const T &  path,
OpenFlags  flags = OpenFlag::Read 
)
inline

open a file by name/path

Parameters
pathfull path to file
flagsopens for opening file
Return values
booltrue on success

◆ operator bool()

IFS::File::operator bool ( ) const
inlineexplicit

◆ read()

int IFS::File::read ( void *  data,
size_t  size 
)
inline

read content from a file and advance cursor

Parameters
databuffer to write into
sizesize of file buffer, maximum number of bytes to read
Return values
intnumber of bytes read or error code

◆ readContent() [1/2]

int IFS::File::readContent ( size_t  size,
ReadContentCallback  callback 
)
inline

Read from current file position and invoke callback for each block read.

Parameters
sizeMaximum number of bytes to read
callback
Return values
intNumber of bytes processed, or error code

◆ readContent() [2/2]

int IFS::File::readContent ( ReadContentCallback  callback)
inline

Read from current file position to end of file and invoke callback for each block read.

Parameters
callback
Return values
intNumber of bytes processed, or error code

◆ remove()

bool IFS::File::remove ( )
inline

remove (delete) an open file (and close it)

Return values
booltrue on success

◆ removeUserAttribute()

bool IFS::File::removeUserAttribute ( uint8_t  tagValue)
inline

◆ seek()

int IFS::File::seek ( int  offset,
SeekOrigin  origin 
)
inline

change file read/write position

Parameters
offsetposition relative to origin
originwhere to seek from (start/end or current position)
Return values
intcurrent position or error code

◆ setacl()

bool IFS::File::setacl ( const ACL acl)
inline

Set access control information for file.

Parameters
acl
Return values
booltrue on success

◆ setAttribute()

template<typename... ParamTypes>
bool IFS::File::setAttribute ( AttributeTag  tag,
ParamTypes...  params 
)
inline

◆ setcompression()

bool IFS::File::setcompression ( const Compression &  compression)
inline

Set file compression information.

Parameters
compression
Return values
booltrue on success

◆ settime()

bool IFS::File::settime ( time_t  mtime)
inline

Set modification time for file.

Return values
booltrue on success
Note
any subsequent writes to file will reset this to current time

◆ setUserAttribute()

template<typename... ParamTypes>
bool IFS::File::setUserAttribute ( uint8_t  tagValue,
ParamTypes...  params 
)
inline

◆ stat()

bool IFS::File::stat ( Stat stat)
inline

get file information

Parameters
statstructure to return information in, may be null
Return values
booltrue on success

◆ tell()

int32_t IFS::File::tell ( )
inline

get current file position

Return values
int32_tcurrent position relative to start of file, or error code

◆ truncate() [1/2]

bool IFS::File::truncate ( size_t  new_size)
inline

Truncate (reduce) the size of an open file.

Parameters
newSize
Return values
booltrue on success

◆ truncate() [2/2]

bool IFS::File::truncate ( )
inline

Truncate an open file at the current cursor position.

Return values
booltrue on success

◆ write() [1/2]

int IFS::File::write ( const void *  data,
size_t  size 
)
inline

write content to a file at current position and advance cursor

Parameters
databuffer to read from
sizenumber of bytes to write
Return values
intnumber of bytes written or error code

◆ write() [2/2]

bool IFS::File::write ( const String s)
inline

Member Data Documentation

◆ Append

constexpr OpenFlags IFS::File::Append {OpenFlag::Append}
static

◆ Create

constexpr OpenFlags IFS::File::Create {OpenFlag::Create}
static

◆ CreateNewAlways

constexpr OpenFlags IFS::File::CreateNewAlways {OpenFlag::Create | OpenFlag::Truncate}
static

◆ ReadOnly

constexpr OpenFlags IFS::File::ReadOnly {OpenFlag::Read}
static

◆ ReadWrite

constexpr OpenFlags IFS::File::ReadWrite {OpenFlag::Read | OpenFlag::Write}
static

◆ Truncate

constexpr OpenFlags IFS::File::Truncate {OpenFlag::Truncate}
static

◆ WriteOnly

constexpr OpenFlags IFS::File::WriteOnly {OpenFlag::Write}
static

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