@@ -490,45 +490,37 @@ onboard_logging.initialize = function (callback) {
490490 show_saving_dialog ( ) ;
491491
492492function onChunkRead ( chunkAddress , chunkDataView , bytesCompressed ) {
493- if ( chunkDataView !== null && chunkDataView . byteLength > 0 ) {
494- // Write whatever we received, even if the block had CRC issues
493+ if ( chunkDataView && chunkDataView . byteLength > 0 ) {
494+ // Always write non-empty data, even if CRC mismatch
495+ const blob = new Blob ( [ chunkDataView ] ) ;
496+ FileSystem . writeChunck ( openedFile , blob ) ;
497+
495498 nextAddress += chunkDataView . byteLength ;
496499
497- if ( isNaN ( bytesCompressed ) || isNaN ( totalBytesCompressed ) ) {
498- totalBytesCompressed = null ;
499- } else {
500+ if ( ! isNaN ( bytesCompressed ) && ! isNaN ( totalBytesCompressed ) ) {
500501 totalBytesCompressed += bytesCompressed ;
502+ } else {
503+ totalBytesCompressed = null ;
501504 }
502505
503506 $ ( ".dataflash-saving progress" ) . attr ( "value" , ( nextAddress / maxBytes ) * 100 ) ;
504507
505- const blob = new Blob ( [ chunkDataView ] ) ;
506- FileSystem . writeChunck ( openedFile , blob ) . then ( ( ) => {
507- if ( saveCancelled || nextAddress >= maxBytes ) {
508- mark_saving_dialog_done ( startTime , nextAddress , totalBytesCompressed ) ;
509- FileSystem . closeFile ( openedFile ) ;
510- } else {
511- mspHelper . dataflashRead ( nextAddress , self . blockSize , onChunkRead ) ;
512- }
513- } ) ;
508+ if ( saveCancelled || nextAddress >= maxBytes ) {
509+ mark_saving_dialog_done ( startTime , nextAddress , totalBytesCompressed ) ;
510+ FileSystem . closeFile ( openedFile ) ;
511+ } else {
512+ mspHelper . dataflashRead ( nextAddress , self . blockSize , onChunkRead ) ;
513+ }
514514
515- } else if ( chunkDataView !== null && chunkDataView . byteLength === 0 ) {
516- // Zero-byte block → end-of-file
515+ } else if ( chunkDataView && chunkDataView . byteLength === 0 ) {
516+ // Zero-length block → EOF
517517 mark_saving_dialog_done ( startTime , nextAddress , totalBytesCompressed ) ;
518518 FileSystem . closeFile ( openedFile ) ;
519519
520520 } else {
521- // CRC or address mismatch
522- console . warn ( `Skipping block at address ${ nextAddress } due to CRC or mismatch` ) ;
523-
524- // If some data arrived (chunkDataView not null), write it anyway
525- if ( chunkDataView && chunkDataView . byteLength > 0 ) {
526- const blob = new Blob ( [ chunkDataView ] ) ;
527- FileSystem . writeChunck ( openedFile , blob ) ;
528- nextAddress += chunkDataView . byteLength ;
529- } else {
530- nextAddress += self . blockSize ;
531- }
521+ // Null block → skip ahead (hard error)
522+ console . warn ( `Skipping null block at address ${ nextAddress } ` ) ;
523+ nextAddress += self . blockSize ;
532524
533525 if ( nextAddress >= maxBytes ) {
534526 mark_saving_dialog_done ( startTime , nextAddress , totalBytesCompressed ) ;
0 commit comments