Skip to content

Commit 08dee6d

Browse files
committedDec 5, 2024
adjustable chunk size
1 parent 0553a89 commit 08dee6d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
 

‎js/appinfo.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ if ("undefined"!=typeof module) {
55
heatshrink = require("../../webtools/heatshrink.js");
66
}
77

8-
// How many bytes of code to we attempt to upload in one go?
9-
const CHUNKSIZE = 1024;
10-
118
// Converts a string into most efficient way to send to Espruino (either json, base64, or compressed base64)
129
function asJSExpr(txt, options) {
1310
/* options = {
@@ -175,8 +172,12 @@ function parseJS(storageFile, options, app) {
175172
var AppInfo = {
176173
/* Get a list of commands needed to upload the file */
177174
getFileUploadCommands : (filename, data) => {
175+
const CHUNKSIZE = Const.UPLOAD_CHUNKSIZE;
178176
if (Const.FILES_IN_FS) {
179-
return `\n\x10require('fs').writeFileSync(${JSON.stringify(filename)},${asJSExpr(data)});`;
177+
let cmd = `\x10require('fs').writeFileSync(${JSON.stringify(filename)},${asJSExpr(data.substr(0,CHUNKSIZE))});`;
178+
for (let i=CHUNKSIZE;i<data.length;i+=CHUNKSIZE)
179+
cmd += `\n\x10require('fs').appendFileSync(${JSON.stringify(filename)},${asJSExpr(data.substr(i,CHUNKSIZE))});`;
180+
return cmd;
180181
} else {
181182
// write code in chunks, in case it is too big to fit in RAM (fix #157)
182183
let cmd = `\x10require('Storage').write(${JSON.stringify(filename)},${asJSExpr(data.substr(0,CHUNKSIZE))},0,${data.length});`;
@@ -187,6 +188,7 @@ var AppInfo = {
187188
},
188189
/* Get a list of commands needed to upload a storage file */
189190
getStorageFileUploadCommands : (filename, data) => {
191+
const CHUNKSIZE = Const.UPLOAD_CHUNKSIZE;
190192
var cmd = "";
191193
// write code in chunks, in case it is too big to fit in RAM (fix #157)
192194
function getWriteData(offset) {

‎js/utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const Const = {
3535
/* If true, store files using 'fs' module which is a FAT filesystem on SD card, not on internal Storage */
3636
FILES_IN_FS : false,
3737

38+
/* How many bytes of code to we attempt to upload in one go? */
39+
UPLOAD_CHUNKSIZE: 1024,
40+
3841
/* Don't try and reset the device when we're connecting/sending apps */
3942
NO_RESET : false,
4043

0 commit comments

Comments
 (0)