@@ -5,9 +5,6 @@ if ("undefined"!=typeof module) {
5
5
heatshrink = require ( "../../webtools/heatshrink.js" ) ;
6
6
}
7
7
8
- // How many bytes of code to we attempt to upload in one go?
9
- const CHUNKSIZE = 1024 ;
10
-
11
8
// Converts a string into most efficient way to send to Espruino (either json, base64, or compressed base64)
12
9
function asJSExpr ( txt , options ) {
13
10
/* options = {
@@ -175,8 +172,12 @@ function parseJS(storageFile, options, app) {
175
172
var AppInfo = {
176
173
/* Get a list of commands needed to upload the file */
177
174
getFileUploadCommands : ( filename , data ) => {
175
+ const CHUNKSIZE = Const . UPLOAD_CHUNKSIZE ;
178
176
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 ;
180
181
} else {
181
182
// write code in chunks, in case it is too big to fit in RAM (fix #157)
182
183
let cmd = `\x10require('Storage').write(${ JSON . stringify ( filename ) } ,${ asJSExpr ( data . substr ( 0 , CHUNKSIZE ) ) } ,0,${ data . length } );` ;
@@ -187,6 +188,7 @@ var AppInfo = {
187
188
} ,
188
189
/* Get a list of commands needed to upload a storage file */
189
190
getStorageFileUploadCommands : ( filename , data ) => {
191
+ const CHUNKSIZE = Const . UPLOAD_CHUNKSIZE ;
190
192
var cmd = "" ;
191
193
// write code in chunks, in case it is too big to fit in RAM (fix #157)
192
194
function getWriteData ( offset ) {
0 commit comments