From 841f154990a1c418bb417f726aa8d64e7201101c Mon Sep 17 00:00:00 2001 From: Kostya Ryabinin <kostya@nulana.com> Date: Tue, 17 Jul 2018 00:56:51 +0500 Subject: [PATCH] sd: implement readBytes --- libraries/SD/src/File.cpp | 5 +++++ libraries/SD/src/SD.h | 1 + 2 files changed, 6 insertions(+) diff --git a/libraries/SD/src/File.cpp b/libraries/SD/src/File.cpp index 380298d1f8..2002f85129 100644 --- a/libraries/SD/src/File.cpp +++ b/libraries/SD/src/File.cpp @@ -95,6 +95,11 @@ int File::read(void *buf, uint16_t nbyte) { return 0; } +size_t File::readBytes(char *buffer, size_t length) { + int result = read(buffer, (uint16_t)length); + return result < 0 ? 0 : (size_t)result; +} + int File::available() { if (! _file) return 0; diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index 38ad793598..9697d12923 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -34,6 +34,7 @@ class File : public Stream { virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buf, size_t size); virtual int read(); + virtual size_t readBytes(char *buffer, size_t length); virtual int peek(); virtual int available(); virtual void flush();