• There are various Apps that are very slow when working out the number of records etc (eg GPS Logger, Accellog) as they have to read through the entire file.

    Wondering if one of the kickstarter improvements could be a ability to read segments of a StorageFile by offset. Currently to get the last line or the record count of a large file you have to read the whole file back. The StorageFile system would have to keep track of file length somehow to do this.

  • You can get the file length with file.getLength() so if you just care about the number of records I'd say guess the length of a line and then just divide the length by that?

    StorageFile reference here: http://www.espruino.com/Reference#StoragĀ­eFile

    It would be possible to add a seek function, However I feel like read at location isn't hugely useful because as you can't store binary data, generally each record is a variable length - so it's not like you can just seek to the end record... You'd have to seek to maybe 100 bytes before the end and then just read lines until you got to the last one.

    I guess what data are you actually trying to find? Is it just that you want to get the final record out of the file, or is it something else?

    I'd actually intended to redo the StorageFile handling such that it could store binary data - and in that case I feel like it would actually be really handy.

  • Ahh - I see now you meant this specifically for accellog.

    Yes, in that case I'd be tempted to use file.getLength()/15 (15 is a guess) to get a fast but 'good enough' length estimate.

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

StorageFile.read(buffer, offset, length, position) ?

Posted by Avatar for HughB @HughB

Actions