From cb66837786647190178893ca880ac743bf286423 Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Sat, 1 Dec 2018 12:18:47 -0500
Subject: [PATCH 01/12] added new boards

---
 boards.txt                        | 60 +++++++++++++++++++++++++++++++
 tools/boards.txt.py               |  2 ++
 tools/sdk/ld/eagle.flash.2m128.ld | 22 ++++++++++++
 tools/sdk/ld/eagle.flash.2m256.ld | 22 ++++++++++++
 4 files changed, 106 insertions(+)
 create mode 100644 tools/sdk/ld/eagle.flash.2m128.ld
 create mode 100644 tools/sdk/ld/eagle.flash.2m256.ld

diff --git a/boards.txt b/boards.txt
index a6e43c8247..30cd1ae389 100644
--- a/boards.txt
+++ b/boards.txt
@@ -189,6 +189,26 @@ generic.menu.eesz.2M.build.flash_ld=eagle.flash.2m.ld
 generic.menu.eesz.2M.build.spiffs_pagesize=256
 generic.menu.eesz.2M.upload.maximum_size=1044464
 generic.menu.eesz.2M.build.rfcal_addr=0x1FC000
+generic.menu.eesz.2M128=2M (128K SPIFFS)
+generic.menu.eesz.2M128.build.flash_size=2M
+generic.menu.eesz.2M128.build.flash_size_bytes=0x200000
+generic.menu.eesz.2M128.build.flash_ld=eagle.flash.2m128.ld
+generic.menu.eesz.2M128.build.spiffs_pagesize=256
+generic.menu.eesz.2M128.upload.maximum_size=1044464
+generic.menu.eesz.2M128.build.rfcal_addr=0x1FC000
+generic.menu.eesz.2M128.build.spiffs_start=0x1E0000
+generic.menu.eesz.2M128.build.spiffs_end=0x1FB000
+generic.menu.eesz.2M128.build.spiffs_blocksize=8192
+generic.menu.eesz.2M256=2M (256K SPIFFS)
+generic.menu.eesz.2M256.build.flash_size=2M
+generic.menu.eesz.2M256.build.flash_size_bytes=0x200000
+generic.menu.eesz.2M256.build.flash_ld=eagle.flash.2m256.ld
+generic.menu.eesz.2M256.build.spiffs_pagesize=256
+generic.menu.eesz.2M256.upload.maximum_size=1044464
+generic.menu.eesz.2M256.build.rfcal_addr=0x1FC000
+generic.menu.eesz.2M256.build.spiffs_start=0x1C0000
+generic.menu.eesz.2M256.build.spiffs_end=0x1FB000
+generic.menu.eesz.2M256.build.spiffs_blocksize=8192
 generic.menu.eesz.2M512=2M (512K SPIFFS)
 generic.menu.eesz.2M512.build.flash_size=2M
 generic.menu.eesz.2M512.build.flash_size_bytes=0x200000
@@ -2421,6 +2441,26 @@ modwifi.menu.eesz.2M.build.flash_ld=eagle.flash.2m.ld
 modwifi.menu.eesz.2M.build.spiffs_pagesize=256
 modwifi.menu.eesz.2M.upload.maximum_size=1044464
 modwifi.menu.eesz.2M.build.rfcal_addr=0x1FC000
+modwifi.menu.eesz.2M128=2M (128K SPIFFS)
+modwifi.menu.eesz.2M128.build.flash_size=2M
+modwifi.menu.eesz.2M128.build.flash_size_bytes=0x200000
+modwifi.menu.eesz.2M128.build.flash_ld=eagle.flash.2m128.ld
+modwifi.menu.eesz.2M128.build.spiffs_pagesize=256
+modwifi.menu.eesz.2M128.upload.maximum_size=1044464
+modwifi.menu.eesz.2M128.build.rfcal_addr=0x1FC000
+modwifi.menu.eesz.2M128.build.spiffs_start=0x1E0000
+modwifi.menu.eesz.2M128.build.spiffs_end=0x1FB000
+modwifi.menu.eesz.2M128.build.spiffs_blocksize=8192
+modwifi.menu.eesz.2M256=2M (256K SPIFFS)
+modwifi.menu.eesz.2M256.build.flash_size=2M
+modwifi.menu.eesz.2M256.build.flash_size_bytes=0x200000
+modwifi.menu.eesz.2M256.build.flash_ld=eagle.flash.2m256.ld
+modwifi.menu.eesz.2M256.build.spiffs_pagesize=256
+modwifi.menu.eesz.2M256.upload.maximum_size=1044464
+modwifi.menu.eesz.2M256.build.rfcal_addr=0x1FC000
+modwifi.menu.eesz.2M256.build.spiffs_start=0x1C0000
+modwifi.menu.eesz.2M256.build.spiffs_end=0x1FB000
+modwifi.menu.eesz.2M256.build.spiffs_blocksize=8192
 modwifi.menu.eesz.2M512=2M (512K SPIFFS)
 modwifi.menu.eesz.2M512.build.flash_size=2M
 modwifi.menu.eesz.2M512.build.flash_size_bytes=0x200000
@@ -5133,6 +5173,26 @@ wifi_slot.menu.eesz.2M.build.flash_ld=eagle.flash.2m.ld
 wifi_slot.menu.eesz.2M.build.spiffs_pagesize=256
 wifi_slot.menu.eesz.2M.upload.maximum_size=1044464
 wifi_slot.menu.eesz.2M.build.rfcal_addr=0x1FC000
+wifi_slot.menu.eesz.2M128=2M (128K SPIFFS)
+wifi_slot.menu.eesz.2M128.build.flash_size=2M
+wifi_slot.menu.eesz.2M128.build.flash_size_bytes=0x200000
+wifi_slot.menu.eesz.2M128.build.flash_ld=eagle.flash.2m128.ld
+wifi_slot.menu.eesz.2M128.build.spiffs_pagesize=256
+wifi_slot.menu.eesz.2M128.upload.maximum_size=1044464
+wifi_slot.menu.eesz.2M128.build.rfcal_addr=0x1FC000
+wifi_slot.menu.eesz.2M128.build.spiffs_start=0x1E0000
+wifi_slot.menu.eesz.2M128.build.spiffs_end=0x1FB000
+wifi_slot.menu.eesz.2M128.build.spiffs_blocksize=8192
+wifi_slot.menu.eesz.2M256=2M (256K SPIFFS)
+wifi_slot.menu.eesz.2M256.build.flash_size=2M
+wifi_slot.menu.eesz.2M256.build.flash_size_bytes=0x200000
+wifi_slot.menu.eesz.2M256.build.flash_ld=eagle.flash.2m256.ld
+wifi_slot.menu.eesz.2M256.build.spiffs_pagesize=256
+wifi_slot.menu.eesz.2M256.upload.maximum_size=1044464
+wifi_slot.menu.eesz.2M256.build.rfcal_addr=0x1FC000
+wifi_slot.menu.eesz.2M256.build.spiffs_start=0x1C0000
+wifi_slot.menu.eesz.2M256.build.spiffs_end=0x1FB000
+wifi_slot.menu.eesz.2M256.build.spiffs_blocksize=8192
 wifi_slot.menu.eesz.2M512=2M (512K SPIFFS)
 wifi_slot.menu.eesz.2M512.build.flash_size=2M
 wifi_slot.menu.eesz.2M512.build.flash_size_bytes=0x200000
diff --git a/tools/boards.txt.py b/tools/boards.txt.py
index 82d899c7e1..deacec0b34 100755
--- a/tools/boards.txt.py
+++ b/tools/boards.txt.py
@@ -1231,6 +1231,8 @@ def all_flash_map ():
     f1m.update( flash_map(    1024,     512 ))
 
     f2m.update( flash_map(  2*1024))
+    f2m.update( flash_map(  2*1024,     128 ))
+    f2m.update( flash_map(  2*1024,     256 ))
     f2m.update( flash_map(  2*1024,     512 ))
     f2m.update( flash_map(  2*1024,    1024 ))
 
diff --git a/tools/sdk/ld/eagle.flash.2m128.ld b/tools/sdk/ld/eagle.flash.2m128.ld
new file mode 100644
index 0000000000..ba04e939c0
--- /dev/null
+++ b/tools/sdk/ld/eagle.flash.2m128.ld
@@ -0,0 +1,22 @@
+/* Flash Split for 2M chips */
+/* sketch @0x40200000 (~1019KB) (1044464B) */
+/* empty  @0x402FEFF0 (~900KB) (921616B) */
+/* spiffs @0x403E0000 (~108KB) (110592B) */
+/* eeprom @0x403FB000 (4KB) */
+/* rfcal  @0x403FC000 (4KB) */
+/* wifi   @0x403FD000 (12KB) */
+
+MEMORY
+{
+  dport0_0_seg :                        org = 0x3FF00000, len = 0x10
+  dram0_0_seg :                         org = 0x3FFE8000, len = 0x14000
+  iram1_0_seg :                         org = 0x40100000, len = 0x8000
+  irom0_0_seg :                         org = 0x40201010, len = 0xfeff0
+}
+
+PROVIDE ( _SPIFFS_start = 0x403E0000 );
+PROVIDE ( _SPIFFS_end = 0x403FB000 );
+PROVIDE ( _SPIFFS_page = 0x100 );
+PROVIDE ( _SPIFFS_block = 0x1000 );
+
+INCLUDE "local.eagle.app.v6.common.ld"
diff --git a/tools/sdk/ld/eagle.flash.2m256.ld b/tools/sdk/ld/eagle.flash.2m256.ld
new file mode 100644
index 0000000000..50610cc42b
--- /dev/null
+++ b/tools/sdk/ld/eagle.flash.2m256.ld
@@ -0,0 +1,22 @@
+/* Flash Split for 2M chips */
+/* sketch @0x40200000 (~1019KB) (1044464B) */
+/* empty  @0x402FEFF0 (~772KB) (790544B) */
+/* spiffs @0x403C0000 (~236KB) (241664B) */
+/* eeprom @0x403FB000 (4KB) */
+/* rfcal  @0x403FC000 (4KB) */
+/* wifi   @0x403FD000 (12KB) */
+
+MEMORY
+{
+  dport0_0_seg :                        org = 0x3FF00000, len = 0x10
+  dram0_0_seg :                         org = 0x3FFE8000, len = 0x14000
+  iram1_0_seg :                         org = 0x40100000, len = 0x8000
+  irom0_0_seg :                         org = 0x40201010, len = 0xfeff0
+}
+
+PROVIDE ( _SPIFFS_start = 0x403C0000 );
+PROVIDE ( _SPIFFS_end = 0x403FB000 );
+PROVIDE ( _SPIFFS_page = 0x100 );
+PROVIDE ( _SPIFFS_block = 0x1000 );
+
+INCLUDE "local.eagle.app.v6.common.ld"

From 70371198cd5abaaa9e87f78c87ae7080045975dd Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Sun, 2 Dec 2018 08:07:31 -0500
Subject: [PATCH 02/12] corrected block size error

---
 tools/sdk/ld/eagle.flash.2m256.ld | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/sdk/ld/eagle.flash.2m256.ld b/tools/sdk/ld/eagle.flash.2m256.ld
index 50610cc42b..db75e86fec 100644
--- a/tools/sdk/ld/eagle.flash.2m256.ld
+++ b/tools/sdk/ld/eagle.flash.2m256.ld
@@ -17,6 +17,6 @@ MEMORY
 PROVIDE ( _SPIFFS_start = 0x403C0000 );
 PROVIDE ( _SPIFFS_end = 0x403FB000 );
 PROVIDE ( _SPIFFS_page = 0x100 );
-PROVIDE ( _SPIFFS_block = 0x1000 );
+PROVIDE ( _SPIFFS_block = 0x2000 );
 
 INCLUDE "local.eagle.app.v6.common.ld"

From 24632aea63a72fe096b8d9dc5852db27e1a95162 Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Thu, 6 Dec 2018 21:07:14 -0500
Subject: [PATCH 03/12] added board to last commit working well

---
 boards.txt                        | 12 ++++++------
 tools/boards.txt.py               |  5 ++++-
 tools/sdk/ld/eagle.flash.2m256.ld |  2 +-
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/boards.txt b/boards.txt
index 30cd1ae389..e8f30778b1 100644
--- a/boards.txt
+++ b/boards.txt
@@ -198,7 +198,7 @@ generic.menu.eesz.2M128.upload.maximum_size=1044464
 generic.menu.eesz.2M128.build.rfcal_addr=0x1FC000
 generic.menu.eesz.2M128.build.spiffs_start=0x1E0000
 generic.menu.eesz.2M128.build.spiffs_end=0x1FB000
-generic.menu.eesz.2M128.build.spiffs_blocksize=8192
+generic.menu.eesz.2M128.build.spiffs_blocksize=4096
 generic.menu.eesz.2M256=2M (256K SPIFFS)
 generic.menu.eesz.2M256.build.flash_size=2M
 generic.menu.eesz.2M256.build.flash_size_bytes=0x200000
@@ -208,7 +208,7 @@ generic.menu.eesz.2M256.upload.maximum_size=1044464
 generic.menu.eesz.2M256.build.rfcal_addr=0x1FC000
 generic.menu.eesz.2M256.build.spiffs_start=0x1C0000
 generic.menu.eesz.2M256.build.spiffs_end=0x1FB000
-generic.menu.eesz.2M256.build.spiffs_blocksize=8192
+generic.menu.eesz.2M256.build.spiffs_blocksize=4096
 generic.menu.eesz.2M512=2M (512K SPIFFS)
 generic.menu.eesz.2M512.build.flash_size=2M
 generic.menu.eesz.2M512.build.flash_size_bytes=0x200000
@@ -2450,7 +2450,7 @@ modwifi.menu.eesz.2M128.upload.maximum_size=1044464
 modwifi.menu.eesz.2M128.build.rfcal_addr=0x1FC000
 modwifi.menu.eesz.2M128.build.spiffs_start=0x1E0000
 modwifi.menu.eesz.2M128.build.spiffs_end=0x1FB000
-modwifi.menu.eesz.2M128.build.spiffs_blocksize=8192
+modwifi.menu.eesz.2M128.build.spiffs_blocksize=4096
 modwifi.menu.eesz.2M256=2M (256K SPIFFS)
 modwifi.menu.eesz.2M256.build.flash_size=2M
 modwifi.menu.eesz.2M256.build.flash_size_bytes=0x200000
@@ -2460,7 +2460,7 @@ modwifi.menu.eesz.2M256.upload.maximum_size=1044464
 modwifi.menu.eesz.2M256.build.rfcal_addr=0x1FC000
 modwifi.menu.eesz.2M256.build.spiffs_start=0x1C0000
 modwifi.menu.eesz.2M256.build.spiffs_end=0x1FB000
-modwifi.menu.eesz.2M256.build.spiffs_blocksize=8192
+modwifi.menu.eesz.2M256.build.spiffs_blocksize=4096
 modwifi.menu.eesz.2M512=2M (512K SPIFFS)
 modwifi.menu.eesz.2M512.build.flash_size=2M
 modwifi.menu.eesz.2M512.build.flash_size_bytes=0x200000
@@ -5182,7 +5182,7 @@ wifi_slot.menu.eesz.2M128.upload.maximum_size=1044464
 wifi_slot.menu.eesz.2M128.build.rfcal_addr=0x1FC000
 wifi_slot.menu.eesz.2M128.build.spiffs_start=0x1E0000
 wifi_slot.menu.eesz.2M128.build.spiffs_end=0x1FB000
-wifi_slot.menu.eesz.2M128.build.spiffs_blocksize=8192
+wifi_slot.menu.eesz.2M128.build.spiffs_blocksize=4096
 wifi_slot.menu.eesz.2M256=2M (256K SPIFFS)
 wifi_slot.menu.eesz.2M256.build.flash_size=2M
 wifi_slot.menu.eesz.2M256.build.flash_size_bytes=0x200000
@@ -5192,7 +5192,7 @@ wifi_slot.menu.eesz.2M256.upload.maximum_size=1044464
 wifi_slot.menu.eesz.2M256.build.rfcal_addr=0x1FC000
 wifi_slot.menu.eesz.2M256.build.spiffs_start=0x1C0000
 wifi_slot.menu.eesz.2M256.build.spiffs_end=0x1FB000
-wifi_slot.menu.eesz.2M256.build.spiffs_blocksize=8192
+wifi_slot.menu.eesz.2M256.build.spiffs_blocksize=4096
 wifi_slot.menu.eesz.2M512=2M (512K SPIFFS)
 wifi_slot.menu.eesz.2M512.build.flash_size=2M
 wifi_slot.menu.eesz.2M512.build.flash_size_bytes=0x200000
diff --git a/tools/boards.txt.py b/tools/boards.txt.py
index deacec0b34..3164096897 100755
--- a/tools/boards.txt.py
+++ b/tools/boards.txt.py
@@ -1125,7 +1125,10 @@ def flash_map (flashsize_kb, spiffs_kb = 0):
     else:
         max_upload_size = 1024 * 1024 - reserved
         spiffs_start = (flashsize_kb - spiffs_kb) * 1024
-        spiffs_blocksize = 8192
+        if spiffs_kb < 512:
+            spiffs_blocksize = 4096
+        else:
+            spiffs_blocksize = 8192
 
     strsize = str(flashsize_kb / 1024) + 'M' if (flashsize_kb >= 1024) else str(flashsize_kb) + 'K'
     strspiffs = str(spiffs_kb / 1024) + 'M' if (spiffs_kb >= 1024) else str(spiffs_kb) + 'K'
diff --git a/tools/sdk/ld/eagle.flash.2m256.ld b/tools/sdk/ld/eagle.flash.2m256.ld
index db75e86fec..50610cc42b 100644
--- a/tools/sdk/ld/eagle.flash.2m256.ld
+++ b/tools/sdk/ld/eagle.flash.2m256.ld
@@ -17,6 +17,6 @@ MEMORY
 PROVIDE ( _SPIFFS_start = 0x403C0000 );
 PROVIDE ( _SPIFFS_end = 0x403FB000 );
 PROVIDE ( _SPIFFS_page = 0x100 );
-PROVIDE ( _SPIFFS_block = 0x2000 );
+PROVIDE ( _SPIFFS_block = 0x1000 );
 
 INCLUDE "local.eagle.app.v6.common.ld"

From 8859aedff6688a7ade77f42aa892b8a390f0dc09 Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Thu, 6 Dec 2018 21:26:54 -0500
Subject: [PATCH 04/12] override of readString for File class
 Stream::readString requires a timeout of 1 seconds + multiple memory resize

---
 cores/esp8266/FS.cpp   | 13 +++++++++++++
 cores/esp8266/FS.h     |  2 ++
 cores/esp8266/Stream.h |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index 6ae11e1782..b67ef72b0b 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -121,6 +121,19 @@ const char* File::name() const {
     return _p->name();
 }
 
+String File::readString()
+{
+    size_t sz = size() - position() - 1;
+    String str;
+    str.reserve(sz);
+	size_t pos=0;
+	while (pos++ < sz)
+    {
+        str += (char)read();
+    }
+    return str;
+}
+
 File Dir::openFile(const char* mode) {
     if (!_impl) {
         return File();
diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h
index 79620f96c8..4a35a6cbf6 100644
--- a/cores/esp8266/FS.h
+++ b/cores/esp8266/FS.h
@@ -73,6 +73,8 @@ class File : public Stream
     operator bool() const;
     const char* name() const;
 
+	String readString() override;
+	
 protected:
     FileImplPtr _p;
 };
diff --git a/cores/esp8266/Stream.h b/cores/esp8266/Stream.h
index 290971cf42..fa786dddc3 100644
--- a/cores/esp8266/Stream.h
+++ b/cores/esp8266/Stream.h
@@ -101,7 +101,7 @@ class Stream: public Print {
         // returns the number of characters placed in the buffer (0 means no valid data found)
 
         // Arduino String functions to be added here
-        String readString();
+        virtual String readString();
         String readStringUntil(char terminator);
 
     protected:

From 9ea55512c5340476461cbbc1416d3b938c424383 Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Thu, 6 Dec 2018 22:01:50 -0500
Subject: [PATCH 05/12] correct indent return if size 0 before reserve

---
 cores/esp8266/FS.cpp | 2 ++
 cores/esp8266/FS.h   | 3 +--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index b67ef72b0b..d488d75695 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -125,6 +125,8 @@ String File::readString()
 {
     size_t sz = size() - position() - 1;
     String str;
+    if (sz<1)
+		return str;
     str.reserve(sz);
 	size_t pos=0;
 	while (pos++ < sz)
diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h
index 4a35a6cbf6..3cf34bb746 100644
--- a/cores/esp8266/FS.h
+++ b/cores/esp8266/FS.h
@@ -72,8 +72,7 @@ class File : public Stream
     void close();
     operator bool() const;
     const char* name() const;
-
-	String readString() override;
+    String readString() override;
 	
 protected:
     FileImplPtr _p;

From dc6b44bde5756b7dd9ccb61cdb15bbe142f9a24d Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Thu, 6 Dec 2018 22:03:23 -0500
Subject: [PATCH 06/12] correct indent

---
 cores/esp8266/FS.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index d488d75695..9f9ccdc843 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -126,7 +126,7 @@ String File::readString()
     size_t sz = size() - position() - 1;
     String str;
     if (sz<1)
-		return str;
+	    return str;
     str.reserve(sz);
 	size_t pos=0;
 	while (pos++ < sz)

From 4fa95271588703ad00ca4402847ffe1a29a4db3f Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Thu, 6 Dec 2018 22:04:48 -0500
Subject: [PATCH 07/12] good indent

---
 cores/esp8266/FS.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index 9f9ccdc843..bafa803387 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -126,10 +126,10 @@ String File::readString()
     size_t sz = size() - position() - 1;
     String str;
     if (sz<1)
-	    return str;
+        return str;
     str.reserve(sz);
-	size_t pos=0;
-	while (pos++ < sz)
+    size_t pos=0;
+    while (pos++ < sz)
     {
         str += (char)read();
     }

From d6088bb3308aa81270ef8fae61bc5360219ce427 Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Fri, 7 Dec 2018 07:15:36 -0500
Subject: [PATCH 08/12] stricter test for end of string

---
 cores/esp8266/FS.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index bafa803387..eb42b350dd 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -123,13 +123,12 @@ const char* File::name() const {
 
 String File::readString()
 {
-    size_t sz = size() - position() - 1;
+    size_t sz = size() - position() + 1;
     String str;
-    if (sz<1)
+    if (sz < 1)
         return str;
     str.reserve(sz);
-    size_t pos=0;
-    while (pos++ < sz)
+    while (available())
     {
         str += (char)read();
     }

From acb99bcb87a49dfecc01ea4038a0437a1355845b Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Fri, 7 Dec 2018 08:00:09 -0500
Subject: [PATCH 09/12] same implementation than Stream by replacing timeRead
 by read

---
 cores/esp8266/FS.cpp | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index eb42b350dd..aead838376 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -123,16 +123,15 @@ const char* File::name() const {
 
 String File::readString()
 {
-    size_t sz = size() - position() + 1;
-    String str;
-    if (sz < 1)
-        return str;
-    str.reserve(sz);
-    while (available())
+    String ret;
+    ret.reserve(size() - position());
+    int c  = read();
+    while (c >= 0)
     {
-        str += (char)read();
+        ret += (char) c;
+        c  = read();
     }
-    return str;
+    return ret;
 }
 
 File Dir::openFile(const char* mode) {

From d16c23cce79752359634c5750bb879a0ec997813 Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Sat, 26 Jan 2019 08:37:32 -0500
Subject: [PATCH 10/12] reading file by block of 256

---
 cores/esp8266/FS.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index aead838376..10c549e95a 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -125,11 +125,12 @@ String File::readString()
 {
     String ret;
     ret.reserve(size() - position());
-    int c  = read();
-    while (c >= 0)
+    char temp[256];
+    int countRead = readBytes(temp, sizeof(temp));
+    while (countRead > 0)
     {
-        ret += (char) c;
-        c  = read();
+        ret += temp;
+        countRead = readBytes(temp, sizeof(temp));
     }
     return ret;
 }

From 9ae9ca1368201ccdd4d6b77f310c5e45efe53fa9 Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Sat, 26 Jan 2019 08:56:15 -0500
Subject: [PATCH 11/12] make sure there is an end of string

---
 cores/esp8266/FS.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index 10c549e95a..80126028ea 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -129,6 +129,8 @@ String File::readString()
     int countRead = readBytes(temp, sizeof(temp));
     while (countRead > 0)
     {
+        if (countRead<sizeof(temp))
+            temp[countRead] = 0;
         ret += temp;
         countRead = readBytes(temp, sizeof(temp));
     }

From d81e55aea7c24d7cb64cb5d2a9adb3413c03eb7f Mon Sep 17 00:00:00 2001
From: Alexandre Picquot <alexandre.picquot@gmail.com>
Date: Wed, 30 Jan 2019 08:10:49 -0500
Subject: [PATCH 12/12] fixed bug for file size multiple of 256
 string::concate(char*) needs a string terminator to work

---
 cores/esp8266/FS.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index 80126028ea..90de4f3c4c 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -125,14 +125,13 @@ String File::readString()
 {
     String ret;
     ret.reserve(size() - position());
-    char temp[256];
-    int countRead = readBytes(temp, sizeof(temp));
+    char temp[256+1];
+    int countRead = readBytes(temp, sizeof(temp)-1);
     while (countRead > 0)
     {
-        if (countRead<sizeof(temp))
-            temp[countRead] = 0;
+        temp[countRead] = 0;
         ret += temp;
-        countRead = readBytes(temp, sizeof(temp));
+        countRead = readBytes(temp, sizeof(temp)-1);
     }
     return ret;
 }