Skip to content

Commit

Permalink
adjustable chunk size
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Dec 5, 2024
1 parent 0553a89 commit 08dee6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions js/appinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ if ("undefined"!=typeof module) {
heatshrink = require("../../webtools/heatshrink.js");
}

// How many bytes of code to we attempt to upload in one go?
const CHUNKSIZE = 1024;

// Converts a string into most efficient way to send to Espruino (either json, base64, or compressed base64)
function asJSExpr(txt, options) {
/* options = {
Expand Down Expand Up @@ -175,8 +172,12 @@ function parseJS(storageFile, options, app) {
var AppInfo = {
/* Get a list of commands needed to upload the file */
getFileUploadCommands : (filename, data) => {
const CHUNKSIZE = Const.UPLOAD_CHUNKSIZE;
if (Const.FILES_IN_FS) {
return `\n\x10require('fs').writeFileSync(${JSON.stringify(filename)},${asJSExpr(data)});`;
let cmd = `\x10require('fs').writeFileSync(${JSON.stringify(filename)},${asJSExpr(data.substr(0,CHUNKSIZE))});`;
for (let i=CHUNKSIZE;i<data.length;i+=CHUNKSIZE)
cmd += `\n\x10require('fs').appendFileSync(${JSON.stringify(filename)},${asJSExpr(data.substr(i,CHUNKSIZE))});`;
return cmd;
} else {
// write code in chunks, in case it is too big to fit in RAM (fix #157)
let cmd = `\x10require('Storage').write(${JSON.stringify(filename)},${asJSExpr(data.substr(0,CHUNKSIZE))},0,${data.length});`;
Expand All @@ -187,6 +188,7 @@ var AppInfo = {
},
/* Get a list of commands needed to upload a storage file */
getStorageFileUploadCommands : (filename, data) => {
const CHUNKSIZE = Const.UPLOAD_CHUNKSIZE;
var cmd = "";
// write code in chunks, in case it is too big to fit in RAM (fix #157)
function getWriteData(offset) {
Expand Down
3 changes: 3 additions & 0 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const Const = {
/* If true, store files using 'fs' module which is a FAT filesystem on SD card, not on internal Storage */
FILES_IN_FS : false,

/* How many bytes of code to we attempt to upload in one go? */
UPLOAD_CHUNKSIZE: 1024,

/* Don't try and reset the device when we're connecting/sending apps */
NO_RESET : false,

Expand Down

0 comments on commit 08dee6d

Please sign in to comment.