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
|
||||
fileContents.forEach(storageFile => {
|
||||
// format ready for Espruino
|
||||
var js;
|
||||
if (storageFile.evaluate) {
|
||||
js = storageFile.content.trim();
|
||||
let js = storageFile.content.trim();
|
||||
if (js.endsWith(";"))
|
||||
js = js.slice(0,-1);
|
||||
} else
|
||||
js = toJS(storageFile.content);
|
||||
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`;
|
||||
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`;
|
||||
} else {
|
||||
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);
|
||||
}).catch(err => reject(err));
|
||||
|
|
|
|||
Loading…
Reference in New Issue