Wraps up all file access methods. More...
#include <File.h>
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) |
file_offset_t | seek (file_offset_t offset, SeekOrigin origin) |
change file read/write position More... | |
bool | eof () |
determine if current file position is at end of file More... | |
file_offset_t | tell () |
get current file position More... | |
bool | truncate (file_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... | |
file_size_t | getSize () |
Get size of file. More... | |
file_offset_t | readContent (size_t size, ReadContentCallback callback) |
Read from current file position and invoke callback for each block read. More... | |
file_offset_t | 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 the file, from current position. More... | |
FileHandle | release () |
Return current file handle and release ownership. More... | |
int | getExtents (Storage::Partition *part, Extent *list, uint16_t extcount) |
FsBase (IFileSystem *filesys=nullptr) | |
![]() | |
FsBase (IFileSystem *filesys=nullptr) | |
bool | isValid () const |
int | getLastError () |
determine if an error occurred during operation More... | |
String | getErrorString (int err) const |
String | getLastErrorString () const |
FileSystem * | getFileSystem () const |
Static Public Attributes | |
Common flag combinations | |
static constexpr OpenFlags | ReadOnly {OpenFlag::Read} |
Read-only. More... | |
static constexpr OpenFlags | WriteOnly {OpenFlag::Write} |
Write-only. More... | |
static constexpr OpenFlags | ReadWrite {OpenFlag::Read | OpenFlag::Write} |
Read + Write. More... | |
static constexpr OpenFlags | Create {OpenFlag::Create} |
Create file if it doesn't exist. More... | |
static constexpr OpenFlags | Append {OpenFlag::Append} |
Append to existing file. More... | |
static constexpr OpenFlags | Truncate {OpenFlag::Truncate} |
Truncate existing file to zero length. More... | |
static constexpr OpenFlags | CreateNewAlways |
Create new file or overwrite file if it exists. More... | |
Additional Inherited Members | |
![]() | |
bool | check (int64_t res) |
Check file operation result and note error code. More... | |
![]() | |
int | lastError {FS_OK} |
Detailed Description
Wraps up all file access methods.
Member Typedef Documentation
◆ ReadContentCallback
Constructor & Destructor Documentation
◆ ~File()
|
inline |
Member Function Documentation
◆ close()
|
inline |
close an open file
- Return values
-
bool true on success
◆ control()
|
inline |
Low-level and non-standard file control operations.
- Parameters
-
code FCNTL_XXX code buffer Input/Output buffer bufSize Size of buffer
- Return values
-
int error 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()
|
inline |
◆ eof()
|
inline |
determine if current file position is at end of file
- Return values
-
bool true if at EOF or file is invalid
◆ flush()
|
inline |
flush any buffered data to physical media
- Return values
-
bool true on success
◆ FsBase()
|
inline |
◆ getAttribute()
|
inline |
◆ getContent()
|
inline |
Read content of the file, from current position.
- 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 "".
◆ getExtents()
|
inline |
◆ getSize()
|
inline |
Get size of file.
- Return values
-
uint32_t Size of file in bytes, 0 on error
◆ getUserAttribute() [1/2]
◆ getUserAttribute() [2/2]
|
inline |
◆ open()
|
inline |
open a file by name/path
- Parameters
-
path full path to file flags opens for opening file
- Return values
-
bool true on success
◆ operator bool()
|
inlineexplicit |
◆ read()
read content from a file and advance cursor
- Parameters
-
data buffer to write into size size of file buffer, maximum number of bytes to read
- Return values
-
int number of bytes read or error code
◆ readContent() [1/2]
|
inline |
Read from current file position to end of file and invoke callback for each block read.
- Parameters
-
callback
- Return values
-
file_offset_t Number of bytes processed, or error code
◆ readContent() [2/2]
|
inline |
Read from current file position and invoke callback for each block read.
- Parameters
-
size Maximum number of bytes to read callback
- Return values
-
int Number of bytes processed, or error code
◆ release()
|
inline |
Return current file handle and release ownership.
◆ remove()
|
inline |
remove (delete) an open file (and close it)
- Return values
-
bool true on success
◆ removeUserAttribute()
◆ seek()
|
inline |
change file read/write position
- Parameters
-
offset position relative to origin origin where to seek from (start/end or current position)
- Return values
-
int current position or error code
◆ setacl()
Set access control information for file.
- Parameters
-
acl
- Return values
-
bool true on success
◆ setAttribute()
|
inline |
◆ setcompression()
|
inline |
Set file compression information.
- Parameters
-
compression
- Return values
-
bool true on success
◆ settime()
|
inline |
Set modification time for file.
- Return values
-
bool true on success
- Note
- any subsequent writes to file will reset this to current time
◆ setUserAttribute()
|
inline |
◆ stat()
get file information
- Parameters
-
stat structure to return information in, may be null
- Return values
-
bool true on success
◆ tell()
|
inline |
get current file position
- Return values
-
int32_t current position relative to start of file, or error code
◆ truncate() [1/2]
|
inline |
Truncate an open file at the current cursor position.
- Return values
-
bool true on success
◆ truncate() [2/2]
|
inline |
Truncate (reduce) the size of an open file.
- Parameters
-
newSize
- Return values
-
bool true on success
◆ write() [1/2]
◆ write() [2/2]
write content to a file at current position and advance cursor
- Parameters
-
data buffer to read from size number of bytes to write
- Return values
-
int number of bytes written or error code
Member Data Documentation
◆ Append
|
staticconstexpr |
Append to existing file.
◆ Create
|
staticconstexpr |
Create file if it doesn't exist.
◆ CreateNewAlways
|
staticconstexpr |
Create new file or overwrite file if it exists.
◆ ReadOnly
|
staticconstexpr |
Read-only.
◆ ReadWrite
|
staticconstexpr |
Read + Write.
◆ Truncate
|
staticconstexpr |
Truncate existing file to zero length.
◆ WriteOnly
|
staticconstexpr |
Write-only.
The documentation for this class was generated from the following file: