Left here for archival purposes.

User avatar
By sadakane
#39453 I tried to read a file of about 1400 bytes but file.read() returns only leading 1024 bytes.

Just the following code prints 1024 while the file "sample.txt" is 1400 bytes.

Code: Select all  file.open("sample.txt","r")
  res = file.read()
  print(string.length(res))
  file.close()


Is this known limitation or bug?


The version I use is:

Code: Select allNodeMCU custom build by frightanic.com
   branch: master
   commit: c8037568571edb5c568c2f8231e4f8ce0683b883
   SSL: false
   modules: node,file,gpio,wifi,net,pwm,tmr,adc,uart,bit,mqtt,coap,cjson,crypto,rc,dht,rtcmem,rtctime,rtcfifo,sntp,enduser_setup
 build    built on: 2016-01-08 10:39
 powered by Lua 5.1.4 on SDK 1.4.0


Thank you.
User avatar
By devsaurus
#39578 Yes, file.read() will return up to max 1024 bytes. This seems to be intended according to the code.
I guess you'd need to read and concatenate the chunks until file.read() returns nil.