FileIO.cpp fix on File::doBuffer()

I searched for a github repository for the Bridge library but i didn’t found it, so i’m posting here

In the file FileIO.cpp, line 121 you have to change

  uint8_t cmd[] = {'G', handle, sizeof(buffer)};


  uint8_t cmd[] = {'G', handle, sizeof(buffer)-1};

otherwise you will lose bytes while reading files largen then the buffer (maybe because of the shift routine at line 127~128)

Thank you for spotting the bug: can you open an issue on the git repo of the IDE? (the cpp side of the bridge is part of it)

I’ve done the changes in FileIO.cpp you suggested but I still have problems with “some” files greater than 63 Bytes. I say “some” files because i can read other files bigger than 63 bytes without problems.
Here the code I use for the test

#include <Console.h>
#include <FileIO.h>
void setup () {
  // wait for the console
  while (!Console); 
    Console.println("Console Ok");
void loop () {
  String fileData;

  File tempFile ="/mnt/sda1/test1.txt", FILE_READ);
  if (tempFile) {
    //Console.println("tempFile = true");
    fileData = "";
    while(tempFile.available()>0) {
      //unsigned int h = tempFile.available();
      Console.print(" ");
      char c =;
      //Console.print(" * ");
      //Console.print(" - ");
      Console.println(c, DEC);
      fileData += c;

I use Console only for debugging.
Attached the 2 files I use for test:

  • test1.txt (63 bytes, give the above mentionned problem)
  • test4.txt (72 bytes, work flawlessy)

Hope somebody could help me.
Thanks in advance.
Fabio Gubler

test1.txt (63 Bytes)

test4.txt (72 Bytes)

Can you give a spin to a nightly version of the IDE? They includes all the latest fixes including that from dreggy and are candidate to be next IDE release

First of all thanks for your message. I've given a try to the nightly version of the IDE. First try : I've inserted in the IDE 1.5.4 the fileio.cpp and fileio.h files taken from the nightly version of the IDE. No luck, problem still present. Second try: I started the full nightly version of the IDE, loading the sketch to test the read from a file written on the SD card behaivour. Again no luck. I' really curious to understand why whit one test file (test4.txt) I haven't problem and with the other one (test1.txt) such strange error appear. Thanks again for your help. Regards. Fabio


I've checked your sketch with file1.txt and the problem randomly happens (about 1 time out of 4 or 5).

Would you like to try to change the /usr/bin/run-bridge script on the yun with the following:


cd /usr/lib/python2.7/bridge

exec python -u 2> /tmp/

I've added the "-u" flag on the last line, that tells python to not line-buffer incoming data from the 32u4. After this change I wasn't able to reproduce the bug, anymore, I want to know how it works for you.


Hi, your suggestion seem to have solved the problem I've pointed out. I've tried several time with different file size and different kind of file and the bug did'nt arose. Thanks a lot for your help. I've declared the issue as solved. :) fabiog45


thank you for the clear bug report and for the feedback ;)