it might not be related to my previous post which is why I created another one.
StorageFile.read() seems to always expect a length argument - but how do I then read a whole file? there is no size method?
But there is another problem: when I try
const Storage = require('Storage');
function compareFileWith (expectedContent) {
let readText = Storage.open('4testing','r').read(1000);
if (readText != expectedContent) {
print('>>>> file does not look as expected');
print('>>>> expected "' + expectedContent + '"');
print('>>>> got "' + readText + '"');
}
}
/**** create file ****/
if (Storage.write('4testing','Hello, World!')) {
print('file "4testing" was successfully created');
} else {
print('file "4testing" could not be created');
}
compareFileWith('Hello, World!');
print('finished');
the file "4testing" is successfully created - but reading it using StorageFile.read produces a strange result:
file "4testing" was successfully created
>>>> file does not look as expected
>>>> expected "Hello, World!"
>>>> got "4testing4testing4testing"
finished
What am I doing wrong?
BTW: I am using the "cutting edge" distribution of today
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hello again,
it might not be related to my previous post which is why I created another one.
StorageFile.read() seems to always expect a
length
argument - but how do I then read a whole file? there is nosize
method?But there is another problem: when I try
the file "4testing" is successfully created - but reading it using
StorageFile.read
produces a strange result:What am I doing wrong?
BTW: I am using the "cutting edge" distribution of today