     }
     f.close();
   }
+  uint8_t *buf = (uint8_t *)malloc(1);
+  int bufLen = 1;
+  int len = 0;
+  {
+    File f = SPIFFS.open(filename, "r");
+    char *oldMachineState = machineState;
+    String oldMachineQue = machineQue;
+    for(int i=0;i<f.size();i++)
+    {
+        int c=f.read();
+        if(c<0)
+          break;
+        buf[0]=c;
+        bufLen = 1;
+        buf = doMaskOuts(buf,&bufLen,maskOuts);
+        buf = doStateMachine(buf,&bufLen,&machineState,&machineQue,stateMachine);
+        len += bufLen;
+    }
+    machineState = oldMachineState;
+    machineQue = oldMachineQue;
+  }
   File f = SPIFFS.open(filename, "r");
-  int len = f.size();
   if(!cache)
   {
     headerOut(0,len,chk8);
     serial.flush(); // stupid important because otherwise apps that go xoff miss the header info
   }
+  len = f.size();
   bool flowControl=!cache;
   BinType streamType = cache?BTYPE_NORMAL:binType;
   int bct=0;

    if(serial.drainForXonXoff()==3)
    {
      serial.setXON(true);
      f.close();
      return ZOK;
    }

      if(serial.drainForXonXoff()==3)
      {
        serial.setXON(true);
        free(buf);
        f.close();
        return ZOK;
      }
