arduino-audio-tools
Loading...
Searching...
No Matches
VFS.h
Go to the documentation of this file.
1#pragma once
3#include "VFSFile.h"
4
5namespace audio_tools {
6
18class VFS {
19 public:
21 virtual bool begin() { return true; }
23 virtual void end() {}
25 virtual void setMountPoint(const char* mp) { mount_point = mp; }
26
27 VFSFile open(const char* file, FileMode mode = VFS_FILE_READ) {
29 vfs_file.open(expand(file), mode);
30 return vfs_file;
31 }
32 VFSFile open(const std::string& path, FileMode mode = VFS_FILE_READ) {
33 const char* path_str = path.c_str();
34 const char* path_str_exanded = expand(path_str);
35 LOGI("open: %s", path_str_exanded);
36 return this->open(path_str_exanded, mode);
37 }
38 bool exists(const char* path) {
39 struct stat buffer;
40 return (stat(expand(path), &buffer) == 0);
41 }
42 bool exists(const std::string& path) { return exists(path.c_str()); }
43 bool remove(const char* path) { return ::remove(expand(path)) == 0; }
44 bool remove(const std::string& path) { return remove(path.c_str()); }
45 bool rename(const char* pathFrom, const char* pathTo) {
46 return ::rename(expand(pathFrom), expand(pathTo)) == 0;
47 }
48 bool rename(const std::string& pathFrom, const std::string& pathTo) {
49 return rename(pathFrom.c_str(), pathTo.c_str());
50 }
51 bool mkdir(const char* path) { return ::mkdir(expand(path), 0777) == 0; }
52 bool mkdir(const std::string& path) { return mkdir(path.c_str()); }
53 bool rmdir(const char* path) { return ::rmdir(expand(path)) == 0; }
54 bool rmdir(const std::string& path) { return rmdir(path.c_str()); }
55
57 const char* mountPoint() { return mount_point; }
58
59 protected:
60 const char* mount_point = "/";
61
63
65 const char* expand(const char* file) {
66 assert(mount_point != nullptr);
67 assert(file != nullptr);
69 if (!StrView(file).startsWith("/") && !StrView(mount_point).endsWith("/")) {
70 tmp.add("/");
71 }
72 tmp.add(file);
73 return tmp.c_str();
74 }
75};
76
77} // namespace audio_tools
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define assert(T)
Definition avr.h:10
Str which keeps the data on the heap. We grow the allocated memory only if the copy source is not fit...
Definition Str.h:24
A simple wrapper to provide string functions on existing allocated char*. If the underlying char* is ...
Definition StrView.h:28
virtual const char * c_str()
provides the string value as const char*
Definition StrView.h:380
virtual void add(int value)
adds a int value
Definition StrView.h:126
Arduino File support using std::fstream.
Definition VFSFile.h:33
void open(const char *name, FileMode mode=VFS_FILE_READ)
Definition VFSFile.h:45
Base class which uses c++ file functions. It is also used as base class for an ESP32 Virtual File Sys...
Definition VFS.h:18
virtual void setMountPoint(const char *mp)
provide the mount point (root directory for the file system)
Definition VFS.h:25
bool remove(const char *path)
Definition VFS.h:43
virtual bool begin()
mount the file systems
Definition VFS.h:21
bool exists(const char *path)
Definition VFS.h:38
bool rmdir(const std::string &path)
Definition VFS.h:54
VFSFile open(const std::string &path, FileMode mode=VFS_FILE_READ)
Definition VFS.h:32
bool mkdir(const std::string &path)
Definition VFS.h:52
VFSFile open(const char *file, FileMode mode=VFS_FILE_READ)
Definition VFS.h:27
bool rmdir(const char *path)
Definition VFS.h:53
const char * mount_point
Definition VFS.h:60
const char * expand(const char *file)
expands the file name with the mount point
Definition VFS.h:65
bool mkdir(const char *path)
Definition VFS.h:51
bool remove(const std::string &path)
Definition VFS.h:44
bool rename(const std::string &pathFrom, const std::string &pathTo)
Definition VFS.h:48
virtual void end()
unmount the file system
Definition VFS.h:23
bool exists(const std::string &path)
Definition VFS.h:42
Str tmp
Definition VFS.h:62
const char * mountPoint()
provides the actual mount point
Definition VFS.h:57
bool rename(const char *pathFrom, const char *pathTo)
Definition VFS.h:45
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
FileMode
Definition VFSFile.h:24
@ VFS_FILE_READ
Definition VFSFile.h:24
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:508