nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.67k stars 3.13k forks source link

file.read(n) reads always 128 bytes #2749

Closed shimosaurus closed 5 years ago

shimosaurus commented 5 years ago

Expected behavior

As example in the doc.

-- print the first 5 bytes of 'init.lua'
fd = file.open("init.lua", "r")
if fd then
  print(fd:read(5))
  fd:close(); fd = nil
end

Actual behavior

Reads always 128 bytes

> print(#fd:read(5))
128
> print(#fd:read(50))
128

Test code

fd = file.open("init.lua", "r")
if fd then
  print(#fd:read(5))
  fd:close(); fd = nil
end

returns 128

NodeMCU version

Breaks in commit c3e24436f2968b8610275fce9b28e3b32588562b Lua string optimisation in file.c + get/put contents methods (#2717)

Hardware

Lolin D1 mini Pro V2.0.0

TerryE commented 5 years ago

@shimosaurus, looks like a good catch. I will check this out.

TerryE commented 5 years ago

Sorry, the logic was flipped on app/modules/file.c:L435. I've just put in a fix to correct this which I have merged in now that the Travis check has completed.