From 9ac36417d1b71f107d20b9a5544ce17d8f0da695 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 15 Jan 2018 14:52:52 +0700 Subject: [PATCH] add Nffs listDir() and catFile() --- libraries/nffs/src/Nffs.cpp | 23 +++++++++++++++++++++++ libraries/nffs/src/Nffs.h | 1 + 2 files changed, 24 insertions(+) diff --git a/libraries/nffs/src/Nffs.cpp b/libraries/nffs/src/Nffs.cpp index 2922ddbf..c46d1bb0 100644 --- a/libraries/nffs/src/Nffs.cpp +++ b/libraries/nffs/src/Nffs.cpp @@ -204,6 +204,7 @@ void ApacheNffs::listDir(const char* cwd) { // Open the input folder NffsDir dir(cwd); + VERIFY ( dir.exists(), ); // File Entry Information which hold file attribute and name NffsDirEntry dirEntry; @@ -232,3 +233,25 @@ void ApacheNffs::listDir(const char* cwd) dir.close(); } + +void ApacheNffs::catFile(const char* fpath, bool isText) +{ + NffsFile f(fpath, FS_ACCESS_READ); + VERIFY ( f.exists(), ); + + uint8_t buffer[128]; + uint32_t count; + + while ( (count = f.read(buffer, sizeof(buffer))) > 0 ) + { + if ( isText ) + { + Serial.write(buffer, count); + }else + { + dbgDumpMemory(buffer, 1, count, true); + } + } + + f.close(); +} diff --git a/libraries/nffs/src/Nffs.h b/libraries/nffs/src/Nffs.h index 6ee90e8d..7c6a648f 100644 --- a/libraries/nffs/src/Nffs.h +++ b/libraries/nffs/src/Nffs.h @@ -86,6 +86,7 @@ public: } void listDir(const char* cwd); + void catFile(const char* fpath, bool isText = false); };