• jsfWriteFile seems to get the wrong dLen(data length), when i enter the code below, i have to encode the data with base64, for some reason(utf8 multibyte Symbol or characters ), some times the data encoded is larger than befor, as use atob(...) when writing to the Storage. for example, the data original is 1000 byte, base64 encoded is 1500 byte, so the question is if i use require('Storage').write("abc.js",atob("­Cmcu...DApOw=="),0,1000); error returned:
    Uncaught Error: Too much data for file size at line 1 col 5563

    use 'require('Storage').write("abc.js",atob(­"Cmcu...DApOw=="),0,1500);' worked fine, but the storage space is wasted a lot ... the final data after base64 decoded just needs 1000 byte :(

  • Hi,

    What does atob("Cmcu...DApOw==").length say?

    If you're just writing a single file, you shouldn't need the ,0,1000 bit - Storage.write will just write a file containing just that data.

    utf8 multibyte Symbol or characters

    If you have these then that is likely your problem. Obviously if you've got 1000 characters, but some of them are multi-byte, then you're going to end up with more than 1000 bytes in your result, which may be what is happening.

    How do you create your base64 encoded string? For instance if you used http://www.espruino.com/File+Converter with a file that was exactly 1000 bytes, I'd be pretty hopeful you would get a 1000 byte value to put in the file

  • thax!
    Yes,i used jswrap_encodeURIComponent before btoa base64 encode for those utf8 multibyte Symbol or characters, and use require('Storage').write("abc.js",decode­URIComponent(atob("Cmcu...DApOw==")),0,1­000); write to the Storage.
    use 0,1000 for slicing as the file little big...
    atob("Cmcu...DApOw==").length is no problem, i'll try to modify the espruino build

  • Just, wasted several precious hours on my own "firmware" #-D
    @Gordon , you r right...
    I tested later that the code worked fine var lengthStr = atob("Cmcu...DApOw==").length;require('S­torage').write("abc.js",atob("Cmcu...DAp­Ow=="),0,lengthStr);
    So, the problem is front end...
    Espruino is perfect! Always!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

jsfWriteFile seems to get the wrong dLen(data length)

Posted by Avatar for tyronehell @tyronehell

Actions