write code in chunks, in case it is too big to fit in RAM (fix #157)
parent
174cc6d7cf
commit
04f8cbcd13
|
|
@ -27,14 +27,19 @@ var AppInfo = {
|
||||||
// then map each file to a command to load into storage
|
// then map each file to a command to load into storage
|
||||||
fileContents.forEach(storageFile => {
|
fileContents.forEach(storageFile => {
|
||||||
// format ready for Espruino
|
// format ready for Espruino
|
||||||
var js;
|
|
||||||
if (storageFile.evaluate) {
|
if (storageFile.evaluate) {
|
||||||
js = storageFile.content.trim();
|
let js = storageFile.content.trim();
|
||||||
if (js.endsWith(";"))
|
if (js.endsWith(";"))
|
||||||
js = js.slice(0,-1);
|
js = js.slice(0,-1);
|
||||||
} else
|
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`;
|
||||||
js = toJS(storageFile.content);
|
} else {
|
||||||
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`;
|
let code = storageFile.content;
|
||||||
|
// write code in chunks, in case it is too big to fit in RAM (fix #157)
|
||||||
|
var CHUNKSIZE = 4096;
|
||||||
|
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${toJS(code.substr(0,CHUNKSIZE))},0,${code.length});`;
|
||||||
|
for (var i=CHUNKSIZE;i<code.length;i+=CHUNKSIZE)
|
||||||
|
storageFile.cmd += `\n\x10require('Storage').write(${toJS(storageFile.name)},${toJS(code.substr(i,CHUNKSIZE))},${i});`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
resolve(fileContents);
|
resolve(fileContents);
|
||||||
}).catch(err => reject(err));
|
}).catch(err => reject(err));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue