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 #include "Data/Stream/SeekOrigin.h"
22 
23 using file_t = signed short;
24 
34 };
35 
37 {
38  return (FileOpenFlags)((int)lhs | (int)rhs);
39 }
40 
45 
51 file_t fileOpen(const String& name, FileOpenFlags flags);
52 
57 void fileClose(file_t file);
58 
65 int fileWrite(file_t file, const void* data, size_t size);
66 
73 int fileRead(file_t file, void* data, size_t size);
74 
81 int fileSeek(file_t file, int offset, SeekOrigin origin);
82 
87 bool fileIsEOF(file_t file);
88 
93 int32_t fileTell(file_t file);
94 
99 int fileFlush(file_t file);
100 
106 int fileLastError(file_t fd);
107 
112 void fileClearLastError(file_t fd);
113 
124 int fileSetContent(const String& fileName, const char* content, int length = -1);
125 
134 int fileSetContent(const String& fileName, const String& content);
135 
141 uint32_t fileGetSize(const String& fileName);
142 
150 int fileTruncate(file_t file, size_t newSize);
151 
156 int fileTruncate(file_t file);
157 
165 int fileTruncate(const String& fileName, size_t newSize);
166 
172 int fileRename(const String& oldName, const String& newName);
173 
179 
187 String fileGetContent(const String& fileName);
188 
199 size_t fileGetContent(const String& fileName, char* buffer, size_t bufSize);
200 
208 int fileStats(const String& name, spiffs_stat* stat);
209 
217 int fileStats(file_t file, spiffs_stat* stat);
218 
223 int fileDelete(const String& name);
224 
229 int fileDelete(file_t file);
230 
235 bool fileExist(const String& name);
236 
Create new file if file does not exist.
Definition: FileSystem.h:30
Truncate file.
Definition: FileSystem.h:32
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.
SEEK_SET: Start of file.
void fileClose(file_t file)
Clode file.
constexpr SeekOrigin eSO_CurrentPos
Definition: FileSystem.h:43
Definition: spiffs.h:297
signed short file_t
File handle.
Definition: FileSystem.h:23
int fileTruncate(file_t file, size_t newSize)
Truncate (reduce) the size of an open file.
constexpr SeekOrigin eSO_FileStart
File seek flags.
Definition: FileSystem.h:42
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.
SEEK_END: End of file.
bool fileExist(const String &name)
Check if a file exists on file system.
#define SPIFFS_APPEND
Definition: spiffs.h:156
SeekOrigin
Stream/file seek origins.
Definition: SeekOrigin.h:18
int fileDelete(const String &name)
Delete file.
int fileSeek(file_t file, int offset, SeekOrigin origin)
Position file cursor.
SEEK_CUR: Current position in file.
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:27
#define SPIFFS_WRONLY
Definition: spiffs.h:168
int fileStats(const String &name, spiffs_stat *stat)
String fileGetContent(const String &fileName)
Read content of a file.
#define SPIFFS_CREAT
Definition: spiffs.h:162
file_t fileOpen(const String &name, FileOpenFlags flags)
Open file.
Append to file.
Definition: FileSystem.h:31
int fileWrite(file_t file, const void *data, size_t size)
Write to file.
#define SPIFFS_RDONLY
Definition: spiffs.h:165
static FileOpenFlags operator|(FileOpenFlags lhs, FileOpenFlags rhs)
Definition: FileSystem.h:36
Create new file even if file exists.
Definition: FileSystem.h:33
constexpr SeekOrigin eSO_FileEnd
Definition: FileSystem.h:44
int fileRename(const String &oldName, const String &newName)
Rename file.
FileOpenFlags
File open flags.
Definition: FileSystem.h:26
int fileFlush(file_t file)
Flush pending writes.
Read and write file.
Definition: FileSystem.h:29
Write only file.
Definition: FileSystem.h:28
uint32_t fileGetSize(const String &fileName)
Get size of file.