You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Yes, this is less than ideal. However the API was only ever intended for Espruino tools, to allow them to upload large files in chunks - hence it's not super user friendly.

    There are a lot of Espruino devices out there now, and the tools that talk to them (some of which are not web based so do not automatically upgrade) pretty much all use this API. I'm not breaking those tools and inconveniencing thousands of users for this (so forcing use of erase is not an option).

    So I'm not sure that even changing offset to a JsVar would solve this (as it'd break existing tools too). I think there are two options:

    • Check if the beginning of the existing file is erased when writing to 0. If it isn't, reallocate the file.
    • Add a new function that can be used to write just part of a file - and maybe even allow it to write to bytes that have already been written.

    Or, if you really want to do this, you can just use the direct flash write API which is easier and maybe more sensible anyway?

    require("Storage").write("x","",0,2048);­
    var addr = E.getAddressOf(require("Storage").read("­x"),true);
    var f = require("Flash");
    
    f.write("Hello world", addr);
    // require("Storage").read("x") == "Hello world\xFF\xFF\xFF...."
    

    Maybe the best thing is just to update the docs with this solution?

About

Avatar for Gordon @Gordon started