mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
LittleFS: add overrides for Stream::send (#8386)
* littlefs: add overrides for Stream::send
This commit is contained in:
parent
d5444c4aa3
commit
2492057b61
@ -118,6 +118,18 @@ public:
|
||||
time_t getCreationTime();
|
||||
void setTimeCallback(time_t (*cb)(void));
|
||||
|
||||
// Stream::send configuration
|
||||
|
||||
bool inputCanTimeout () override {
|
||||
// unavailable data can't become later available
|
||||
return false;
|
||||
}
|
||||
|
||||
bool outputCanTimeout () override {
|
||||
// free space for write can't increase later
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
FileImplPtr _p;
|
||||
time_t (*_timeCallback)(void) = nullptr;
|
||||
|
@ -132,6 +132,16 @@ void DoTest(FS *fs) {
|
||||
f.close();
|
||||
stop = millis();
|
||||
Serial.printf("==> Time to read 64KB in 1b chunks = %lu milliseconds = %s\n", stop - start, rate(start, stop, 65536));
|
||||
|
||||
|
||||
start = millis();
|
||||
auto dest = fs->open("/test1bw.bin", "w");
|
||||
f = fs->open("/test1b.bin", "r");
|
||||
auto copysize = f.sendAll(dest);
|
||||
dest.close();
|
||||
stop = millis();
|
||||
Serial.printf("==> Time to copy %d = %zd bytes = %lu milliseconds = %s\n", f.size(), copysize, stop - start, rate(start, stop, f.size()));
|
||||
f.close();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@ -139,6 +149,7 @@ void setup() {
|
||||
Serial.printf("Beginning test\n");
|
||||
Serial.flush();
|
||||
DoTest(&TESTFS);
|
||||
Serial.println("done");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -241,7 +241,7 @@ public:
|
||||
DEBUGV("lfs_format, lfs_setattr 't': rc=%d\n", rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
lfs_unmount(&_lfs);
|
||||
_mounted = false;
|
||||
}
|
||||
@ -372,6 +372,30 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
int availableForWrite () override {
|
||||
if (!_opened || !_fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto f = _getFD();
|
||||
const auto fs = _fs->getFS();
|
||||
|
||||
// check for remaining size in current block
|
||||
// ignore inline feature (per code in lfs_file_rawwrite())
|
||||
auto afw = fs->cfg->block_size - f->off;
|
||||
|
||||
if (afw == 0) {
|
||||
// current block is full
|
||||
// check for filesystem full (per code in lfs_alloc())
|
||||
if (!(fs->free.i == fs->free.size && fs->free.ack == 0)) {
|
||||
// fs is not full, return a full sector as free space
|
||||
afw = fs->cfg->block_size;
|
||||
}
|
||||
}
|
||||
|
||||
return afw;
|
||||
}
|
||||
|
||||
size_t write(const uint8_t *buf, size_t size) override {
|
||||
if (!_opened || !_fd || !buf) {
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user