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#StorageFile
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.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem