FileSystem.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * FileSystem.h
8  *
9  ****/
10 
16 #pragma once
17 
18 #include <spiffs_sming.h>
19 #include <WVector.h>
20 #include <WString.h>
21 
22 typedef signed short file_t;
23 
33 };
34 
36 {
37  return (FileOpenFlags)((int)lhs | (int)rhs);
38 }
39 
41 typedef enum {
46 
52 file_t fileOpen(const String& name, FileOpenFlags flags);
53 
58 void fileClose(file_t file);
59 
66 int fileWrite(file_t file, const void* data, size_t size);
67 
74 int fileRead(file_t file, void* data, size_t size);
75 
82 int fileSeek(file_t file, int offset, SeekOriginFlags origin);
83 
88 bool fileIsEOF(file_t file);
89 
94 int32_t fileTell(file_t file);
95 
100 int fileFlush(file_t file);
101 
107 int fileLastError(file_t fd);
108 
113 void fileClearLastError(file_t fd);
114 
125 int fileSetContent(const String& fileName, const char* content, int length = -1);
126 
135 int fileSetContent(const String& fileName, const String& content);
136 
142 uint32_t fileGetSize(const String& fileName);
143 
151 int fileTruncate(file_t file, size_t newSize);
152 
157 int fileTruncate(file_t file);
158 
166 int fileTruncate(const String& fileName, size_t newSize);
167 
173 int fileRename(const String& oldName, const String& newName);
174 
180 
188 String fileGetContent(const String& fileName);
189 
200 size_t fileGetContent(const String& fileName, char* buffer, size_t bufSize);
201 
209 int fileStats(const String& name, spiffs_stat* stat);
210 
218 int fileStats(file_t file, spiffs_stat* stat);
219 
224 int fileDelete(const String& name);
225 
230 int fileDelete(file_t file);
231 
236 bool fileExist(const String& name);
237 
SeekOriginFlags
File seek flags.
Definition: FileSystem.h:41
Create new file if file does not exist.
Definition: FileSystem.h:29
Truncate file.
Definition: FileSystem.h:31
int32_t fileTell(file_t file)
Get position in file.
int fileSetContent(const String &fileName, const char *content, int length=-1)
Create or replace file with defined content.
int fileRead(file_t file, void *data, size_t size)
Read from file.
void fileClose(file_t file)
Clode file.
Definition: spiffs.h:297
int fileTruncate(file_t file, size_t newSize)
Truncate (reduce) the size of an open file.
The String class.
Definition: WString.h:136
void fileClearLastError(file_t fd)
Clear last file system error.
int fileLastError(file_t fd)
Get last file system error code.
bool fileExist(const String &name)
Check if a file exists on file system.
#define SPIFFS_APPEND
Definition: spiffs.h:156
int fileDelete(const String &name)
Delete file.
Current position in file.
Definition: FileSystem.h:43
bool fileIsEOF(file_t file)
Check if at end of file.
#define SPIFFS_TRUNC
Definition: spiffs.h:159
Vector< String > fileList()
Get list of files on file system.
Read only file.
Definition: FileSystem.h:26
#define SPIFFS_WRONLY
Definition: spiffs.h:168
int fileStats(const String &name, spiffs_stat *stat)
signed short file_t
File handle.
Definition: FileSystem.h:22
String fileGetContent(const String &fileName)
Read content of a file.
End of file.
Definition: FileSystem.h:44
#define SPIFFS_CREAT
Definition: spiffs.h:162
file_t fileOpen(const String &name, FileOpenFlags flags)
Open file.
Append to file.
Definition: FileSystem.h:30
int fileWrite(file_t file, const void *data, size_t size)
Write to file.
#define SPIFFS_SEEK_END
Definition: spiffs.h:182
#define SPIFFS_RDONLY
Definition: spiffs.h:165
static FileOpenFlags operator|(FileOpenFlags lhs, FileOpenFlags rhs)
Definition: FileSystem.h:35
Start of file.
Definition: FileSystem.h:42
Create new file even if file exists.
Definition: FileSystem.h:32
#define SPIFFS_SEEK_SET
Definition: spiffs.h:180
int fileRename(const String &oldName, const String &newName)
Rename file.
#define SPIFFS_SEEK_CUR
Definition: spiffs.h:181
FileOpenFlags
File open flags.
Definition: FileSystem.h:25
int fileFlush(file_t file)
Flush pending writes.
Read and write file.
Definition: FileSystem.h:28
int fileSeek(file_t file, int offset, SeekOriginFlags origin)
Position file cursor.
Write only file.
Definition: FileSystem.h:27
uint32_t fileGetSize(const String &fileName)
Get size of file.