SdFs
Public Member Functions | List of all members
ExFile Class Reference

exFAT file with Arduino Stream. More...

#include <ExFatFile.h>

Inheritance diagram for ExFile:
Inheritance graph
[legend]
Collaboration diagram for ExFile:
Collaboration graph
[legend]

Public Member Functions

int available ()
 
uint64_t available64 ()
 
void clearError ()
 
void clearWriteError ()
 
bool close ()
 
uint64_t curPosition () const
 
uint64_t dataLength ()
 
bool exists (const ExChar_t *path)
 
void fgetpos (fspos_t *pos)
 
int fgets (char *str, int num, char *delim=nullptr)
 
uint64_t fileSize ()
 
void flush ()
 
void fsetpos (fspos_t *pos)
 
uint8_t getError ()
 
size_t getName (ExChar_t *name, size_t size)
 
bool getWriteError ()
 
bool isContiguous () const
 
bool isDir () const
 
bool isDirectory ()
 
bool isFile () const
 
bool isHidden () const
 
bool isOpen () const
 
bool isReadable () const
 
bool isReadOnly () const
 
bool isRoot () const
 
bool isSubDir () const
 
bool isWritable () const
 
void ls (print_t *pr)
 
void ls (print_t *pr, uint8_t flags, uint8_t indent=0)
 
bool mkdir (ExFatFile *parent, const ExChar_t *path, bool pFlag=true)
 
int mprintf (const char *fmt,...)
 
const char * name () const
 
bool open (ExFatFile *dirFile, const ExChar_t *path, uint8_t oflag)
 
bool open (ExFatVolume *vol, const ExChar_t *path, int oflag)
 
bool open (const ExChar_t *path, int oflag=O_READ)
 
bool openNext (ExFatFile *dirFile, uint8_t oflag=O_READ)
 
ExFile openNextFile (uint8_t mode=O_READ)
 
bool openRoot (ExFatVolume *vol)
 
 operator bool ()
 
int peek ()
 
uint64_t position ()
 
bool preAllocate (uint64_t length)
 
size_t printCreateDateTime (print_t *pr)
 
int printf (const char *fmt,...)
 
int printField (int16_t value, char term)
 
int printField (uint16_t value, char term)
 
int printField (int32_t value, char term)
 
int printField (uint32_t value, char term)
 
size_t printFileSize (print_t *pr)
 
size_t printModifyDateTime (print_t *pr)
 
size_t printName (print_t *pr)
 
int read ()
 
int read (void *buf, size_t count)
 
bool remove ()
 
bool remove (const ExChar_t *path)
 
bool rename (const ExChar_t *newPath)
 
bool rename (ExFatFile *dirFile, const ExChar_t *newPath)
 
void rewind ()
 
void rewindDirectory ()
 
bool rmdir ()
 
bool seek (uint64_t pos)
 
bool seekCur (int64_t offset)
 
bool seekEnd (int64_t offset=0)
 
bool seekSet (uint64_t pos)
 
uint64_t size ()
 
bool sync ()
 
bool truncate ()
 
bool truncate (uint64_t length)
 
uint64_t validLength ()
 
size_t write (uint8_t b)
 
int write (const char *str)
 
size_t write (const void *buf, size_t count)
 

Detailed Description

exFAT file with Arduino Stream.

Member Function Documentation

int StreamFile< ExFatFile , uint64_t >::available ( )
inlineinherited
Returns
number of bytes available from the current position to EOF or INT_MAX if more than INT_MAX bytes are available.
uint64_t ExFatFile::available64 ( )
inlineinherited
Returns
The number of bytes available from the current position to EOF for normal files. Zero is returned for directory files.
void ExFatFile::clearError ( )
inlineinherited

Clear all error bits.

void ExFatFile::clearWriteError ( )
inlineinherited

Set writeError to zero

bool ExFatFile::close ( )
inherited

Close a file and force cached data and directory information to be written to the storage device.

Returns
The value true is returned for success and the value false is returned for failure.

Copyright (c) 20011-2017 Bill Greiman This file is part of the SdFs library for SD memory cards.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

uint64_t ExFatFile::curPosition ( ) const
inlineinherited
Returns
The current position for a file or directory.
uint64_t ExFatFile::dataLength ( )
inlineinherited
Returns
Total data length for file.
bool ExFatFile::exists ( const ExChar_t *  path)
inlineinherited

Test for the existence of a file in a directory

Parameters
[in]pathPath of the file to be tested for.

The calling instance must be an open directory file.

dirFile.exists("TOFIND.TXT") searches for "TOFIND.TXT" in the directory dirFile.

Returns
true if the file exists else false.
void ExFatFile::fgetpos ( fspos_t *  pos)
inherited

get position for streams

Parameters
[out]posstruct to receive position
int ExFatFile::fgets ( char *  str,
int  num,
char *  delim = nullptr 
)
inherited

Get a string from a file.

fgets() reads bytes from a file into the array pointed to by str, until num - 1 bytes are read, or a delimiter is read and transferred to str, or end-of-file is encountered. The string is then terminated with a null byte.

fgets() deletes CR, '\r', from the string. This insures only a '\n' terminates the string for Windows text files which use CRLF for newline.

Parameters
[out]strPointer to the array where the string is stored.
[in]numMaximum number of characters to be read (including the final null byte). Usually the length of the array str is used.
[in]delimOptional set of delimiters. The default is "\n".
Returns
For success fgets() returns the length of the string in str. If no data is read, fgets() returns zero for EOF or -1 if an error occurred.
uint64_t ExFatFile::fileSize ( )
inlineinherited
Returns
The total number of bytes in a file.
void StreamFile< ExFatFile , uint64_t >::flush ( )
inlineinherited

Ensure that any bytes written to the file are saved to the SD card.

void ExFatFile::fsetpos ( fspos_t *  pos)
inherited

set position for streams

Parameters
[out]posstruct with value for new position
uint8_t ExFatFile::getError ( )
inlineinherited
Returns
All error bits.
size_t ExFatFile::getName ( ExChar_t *  name,
size_t  size 
)
inherited

Get a file's name followed by a zero byte.

Parameters
[out]nameAn array of characters for the file's name.
[in]sizeThe size of the array in characters.
Returns
the name length.
bool ExFatFile::getWriteError ( )
inlineinherited
Returns
value of writeError
bool ExFatFile::isContiguous ( ) const
inlineinherited
Returns
True if the file is contiguous.
bool ExFatFile::isDir ( ) const
inlineinherited
Returns
True if this is a directory.
bool StreamFile< ExFatFile , uint64_t >::isDirectory ( )
inlineinherited

This function reports if the current file is a directory or not.

Returns
true if the file is a directory.
bool ExFatFile::isFile ( ) const
inlineinherited
Returns
True if this is a normal file.
bool ExFatFile::isHidden ( ) const
inlineinherited
Returns
True if this is a hidden.
bool ExFatFile::isOpen ( ) const
inlineinherited
Returns
true if the file is open.
bool ExFatFile::isReadable ( ) const
inlineinherited
Returns
True file is writable.
bool ExFatFile::isReadOnly ( ) const
inlineinherited
Returns
True if file is read-only
bool ExFatFile::isRoot ( ) const
inlineinherited
Returns
True if this is the root directory.
bool ExFatFile::isSubDir ( ) const
inlineinherited
Returns
True if this is a subdirectory.
bool ExFatFile::isWritable ( ) const
inlineinherited
Returns
True file is writable.
void ExFatFile::ls ( print_t *  pr)
inherited

List directory contents.

Parameters
[in]prPrint stream for list.
void ExFatFile::ls ( print_t *  pr,
uint8_t  flags,
uint8_t  indent = 0 
)
inherited

List directory contents.

Parameters
[in]prPrint stream for list.
[in]flagsThe inclusive OR of

LS_DATE - Print file modification date

LS_SIZE - Print file size.

LS_R - Recursive list of subdirectories.

Parameters
[in]indentAmount of space before file name. Used for recursive list to indicate subdirectory level.
bool ExFatFile::mkdir ( ExFatFile parent,
const ExChar_t *  path,
bool  pFlag = true 
)
inherited

Make a new directory.

Parameters
[in]parentAn open directory file that will contain the new directory.
[in]pathA path with a valid name for the new directory.
[in]pFlagCreate missing parent directories if true.
Returns
The value true is returned for success and the value false is returned for failure.
int ExFatFile::mprintf ( const char *  fmt,
  ... 
)
inherited

Formatted print.

Parameters
[in]fmtformat string.
Returns
number of character printed for success else a negative value.
const char* StreamFile< ExFatFile , uint64_t >::name ( ) const
inlineinherited

No longer implemented due to Long File Names.

Use getName(char* name, size_t size).

Returns
a pointer to replacement suggestion.
bool ExFatFile::open ( ExFatFile dirFile,
const ExChar_t *  path,
uint8_t  oflag 
)
inherited

Open a file or directory by name.

Parameters
[in]dirFileAn open directory containing the file to be opened.
[in]pathThe path for a file to be opened.
[in]oflagValues for oflag are constructed by a bitwise-inclusive OR of flags from the following list

O_READ - Open for reading.

O_RDONLY - Same as O_READ.

O_WRITE - Open for writing.

O_WRONLY - Same as O_WRITE.

O_RDWR - Open for reading and writing.

O_APPEND - If set, the file offset shall be set to the end of the file prior to each write.

O_AT_END - Set the initial position at the end of the file.

O_CREAT - If the file exists, this flag has no effect except as noted under O_EXCL below. Otherwise, the file shall be created

O_EXCL - If O_CREAT and O_EXCL are set, open() shall fail if the file exists.

O_TRUNC - If the file exists and is a regular file, and the file is successfully opened and is not read only, its length shall be truncated to 0.

WARNING: A given file must not be opened by more than one file object or file corruption may occur.

Note
Directory files must be opened read only. Write and truncation is not allowed for directory files.
Returns
The value true is returned for success and the value false is returned for failure.
bool ExFatFile::open ( ExFatVolume vol,
const ExChar_t *  path,
int  oflag 
)
inherited

Open a file in the volume root directory.

Parameters
[in]volVolume where the file is located.
[in]pathwith a valid name for a file to be opened.
[in]oflagbitwise-inclusive OR of open mode flags. See see open(ExFatFile*, const char*, uint8_t).
Returns
The value true is returned for success and the value false is returned for failure.
bool ExFatFile::open ( const ExChar_t *  path,
int  oflag = O_READ 
)
inherited

Open a file in the current working directory.

Parameters
[in]pathA path with a valid name for a file to be opened.
[in]oflagbitwise-inclusive OR of open mode flags. See see FatFile::open(FatFile*, const char*, uint8_t).
Returns
The value true is returned for success and the value false is returned for failure.
bool ExFatFile::openNext ( ExFatFile dirFile,
uint8_t  oflag = O_READ 
)
inherited

Open the next file or subdirectory in a directory.

Parameters
[in]dirFileAn open instance for the directory containing the file to be opened.
[in]oflagbitwise-inclusive OR of open mode flags. See see open(ExFatFile*, const char*, uint8_t).
Returns
true for success or false for failure.
ExFile ExFile::openNextFile ( uint8_t  mode = O_READ)
inline

Opens the next file or folder in a directory.

Parameters
[in]modeopen mode flags.
Returns
a FatStream object.
bool ExFatFile::openRoot ( ExFatVolume vol)
inherited

Open a volume's root directory.

Parameters
[in]volThe FAT volume containing the root directory to be opened.
Returns
The value true is returned for success and the value false is returned for failure.
ExFatFile::operator bool ( )
inlineinherited

The parenthesis operator.

Returns
true if a file is open.
int StreamFile< ExFatFile , uint64_t >::peek ( )
inlineinherited

Return the next available byte without consuming it.

Returns
The byte if no error and not at eof else -1;
uint64_t StreamFile< ExFatFile , uint64_t >::position ( )
inlineinherited
Returns
the current file position.
bool ExFatFile::preAllocate ( uint64_t  length)
inherited

Allocate contiguous clusters to an empty file.

The file must be empty with no clusters allocated.

The file will have zero validLength and dataLength will equal the requested length.

Parameters
[in]lengthsize of allocated space in bytes.
Returns
true for success else false.
size_t ExFatFile::printCreateDateTime ( print_t *  pr)
inherited

Print a file's modify date and time

Parameters
[in]prPrint stream for output.
Returns
The value true is returned for success and the value false is returned for failure.
int ExFatFile::printf ( const char *  fmt,
  ... 
)
inherited

Formatted print.

Parameters
[in]fmtformat string.
Returns
number of character printed for success else a negative value.
int ExFatFile::printField ( int16_t  value,
char  term 
)
inherited

Print a number followed by a field terminator.

Parameters
[in]valueThe number to be printed.
[in]termThe field terminator. Use '\n' for CR LF.
Returns
The number of bytes written or -1 if an error occurs.
int ExFatFile::printField ( uint16_t  value,
char  term 
)
inherited

Print a number followed by a field terminator.

Parameters
[in]valueThe number to be printed.
[in]termThe field terminator. Use '\n' for CR LF.
Returns
The number of bytes written or -1 if an error occurs.
int ExFatFile::printField ( int32_t  value,
char  term 
)
inherited

Print a number followed by a field terminator.

Parameters
[in]valueThe number to be printed.
[in]termThe field terminator. Use '\n' for CR LF.
Returns
The number of bytes written or -1 if an error occurs.
int ExFatFile::printField ( uint32_t  value,
char  term 
)
inherited

Print a number followed by a field terminator.

Parameters
[in]valueThe number to be printed.
[in]termThe field terminator. Use '\n' for CR LF.
Returns
The number of bytes written or -1 if an error occurs.
size_t ExFatFile::printFileSize ( print_t *  pr)
inherited

Print a file's size in bytes.

Parameters
[in]prPrtin stream for the output.
Returns
The number of bytes printed.

Copyright (c) 20011-2017 Bill Greiman This file is part of the SdFs library for SD memory cards.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

size_t ExFatFile::printModifyDateTime ( print_t *  pr)
inherited

Print a file's modify date and time

Parameters
[in]prPrint stream for output.
Returns
The value true is returned for success and the value false is returned for failure.
size_t ExFatFile::printName ( print_t *  pr)
inherited

Print a file's name

Parameters
[in]prPrint stream for output.
Returns
The value true is returned for success and the value false is returned for failure.
int StreamFile< ExFatFile , uint64_t >::read ( )
inlineinherited

Read the next byte from a file.

Returns
For success return the next byte in the file as an int. If an error occurs or end of file is reached return -1.
int ExFatFile::read ( void *  buf,
size_t  count 
)
inherited

Read data from a file starting at the current position.

Parameters
[out]bufPointer to the location that will receive the data.
[in]countMaximum number of bytes to read.
Returns
For success read() returns the number of bytes read. A value less than nbyte, including zero, will be returned if end of file is reached. If an error occurs, read() returns -1.
bool ExFatFile::remove ( )
inherited

Remove a file.

The directory entry and all data for the file are deleted.

Note
This function should not be used to delete the 8.3 version of a file that has a long name. For example if a file has the long name "New Text Document.txt" you should not delete the 8.3 name "NEWTEX~1.TXT".
Returns
The value true is returned for success and the value false is returned for failure.
bool ExFatFile::remove ( const ExChar_t *  path)
inherited

Remove a file.

The directory entry and all data for the file are deleted.

Parameters
[in]pathPath for the file to be removed.

Example use: dirFile.remove(filenameToRemove);

Note
This function should not be used to delete the 8.3 version of a file that has a long name. For example if a file has the long name "New Text Document.txt" you should not delete the 8.3 name "NEWTEX~1.TXT".
Returns
The value true is returned for success and the value false is returned for failure.
bool ExFatFile::rename ( const ExChar_t *  newPath)
inherited

Rename a file or subdirectory.

Parameters
[in]newPathNew path name for the file/directory.
Returns
The value true is returned for success and the value false is returned for failure.
bool ExFatFile::rename ( ExFatFile dirFile,
const ExChar_t *  newPath 
)
inherited

Rename a file or subdirectory.

Parameters
[in]dirFileDirectory for the new path.
[in]newPathNew path name for the file/directory.
Returns
The value true is returned for success and the value false is returned for failure.
void ExFatFile::rewind ( )
inlineinherited

Set the file's current position to zero.

void StreamFile< ExFatFile , uint64_t >::rewindDirectory ( )
inlineinherited

Rewind a file if it is a directory

bool ExFatFile::rmdir ( )
inherited

Remove a directory file.

The directory file will be removed only if it is empty and is not the root directory. rmdir() follows DOS and Windows and ignores the read-only attribute for the directory.

Note
This function should not be used to delete the 8.3 version of a directory that has a long name. For example if a directory has the long name "New folder" you should not delete the 8.3 name "NEWFOL~1".
Returns
The value true is returned for success and the value false is returned for failure.
bool StreamFile< ExFatFile , uint64_t >::seek ( uint64_t  pos)
inlineinherited

Seek to a new position in the file, which must be between 0 and the size of the file (inclusive).

Parameters
[in]posthe new file position.
Returns
true for success else false.
bool ExFatFile::seekCur ( int64_t  offset)
inlineinherited

Set the files position to current position + pos. See seekSet().

Parameters
[in]offsetThe new position in bytes from the current position.
Returns
true for success or false for failure.
bool ExFatFile::seekEnd ( int64_t  offset = 0)
inlineinherited

Set the files position to end-of-file + offset. See seekSet(). Can't be used for directory files since file size is not defined.

Parameters
[in]offsetThe new position in bytes from end-of-file.
Returns
true for success or false for failure.
bool ExFatFile::seekSet ( uint64_t  pos)
inherited

Sets a file's position.

Parameters
[in]posThe new position in bytes from the beginning of the file.
Returns
The value true is returned for success and the value false is returned for failure.
uint64_t StreamFile< ExFatFile , uint64_t >::size ( )
inlineinherited
Returns
the file's size.
bool ExFatFile::sync ( )
inherited

The sync() call causes all modified data and directory fields to be written to the storage device.

Returns
The value true is returned for success and the value false is returned for failure.
bool ExFatFile::truncate ( )
inherited

Truncate a file at the current file position.

Returns
The value true is returned for success and the value false is returned for failure.
bool ExFatFile::truncate ( uint64_t  length)
inlineinherited

Truncate a file to a specified length. The current file position will be set to end of file.

Parameters
[in]lengthThe desired length for the file.
Returns
The value true is returned for success and the value false is returned for failure.
uint64_t ExFatFile::validLength ( )
inlineinherited
Returns
The valid number of bytes in a file.
size_t StreamFile< ExFatFile , uint64_t >::write ( uint8_t  b)
inlineinherited

Write a byte to a file. Required by the Arduino Print class.

Parameters
[in]bthe byte to be written. Use getWriteError to check for errors.
Returns
1 for success and 0 for failure.
int ExFatFile::write ( const char *  str)
inlineinherited

Write a string to a file. Used by the Arduino Print class.

Parameters
[in]strPointer to the string. Use getWriteError to check for errors.
Returns
count of characters written for success or -1 for failure.
size_t ExFatFile::write ( const void *  buf,
size_t  count 
)
inherited

Write data to an open file.

Note
Data is moved to the cache but may not be written to the storage device until sync() is called.
Parameters
[in]bufPointer to the location of the data to be written.
[in]countNumber of bytes to write.
Returns
For success write() returns the number of bytes written, always count.

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