lib/connector/upload.js
async function writeChunk(){
        if (chunks.length > 0){
            // get first element
            const l = chunks.shift();

            // increment size counter
            currentUploadSize += l.length;

            // write first element to file
            try{
                await _virtualTerminal.executeCommand('__nmtwrite("' + l + '")');
            }catch(e){
                _logger.debug(e);
                throw new Error('cannot write chunk to remote file');
            }

            // run progress callback
            progressCb.apply(progressCb, [currentUploadSize, absoluteFilesize]);

            // write next
            await writeChunk();

        }else{
            // ensure that the progress callback is called, even for empty files
            progressCb.apply(progressCb, [currentUploadSize, absoluteFilesize]);

            // send file close command
            try{
                await _virtualTerminal.executeCommand(_luaCommandBuilder.command.fileCloseFlush);
            }catch(e){
                _logger.debug(e);
                throw new Error('cannot flush/close remote file');
            }
        }
    }
async function writeChunk(){
        if (chunks.length > 0){
            // get first element
            const l = chunks.shift();

            // increment size counter
            currentUploadSize += l.length;

            // write first element to file
            try{
                await _virtualTerminal.executeCommand('__nmtwrite("' + l + '")');
            }catch(e){
                _logger.debug(e);
                throw new Error('cannot write chunk to remote file');
            }

            // run progress callback
            progressCb.apply(progressCb, [currentUploadSize, absoluteFilesize]);

            // write next
            await writeChunk();

        }else{
            // ensure that the progress callback is called, even for empty files
            progressCb.apply(progressCb, [currentUploadSize, absoluteFilesize]);

            // send file close command
            try{
                await _virtualTerminal.executeCommand(_luaCommandBuilder.command.fileCloseFlush);
            }catch(e){
                _logger.debug(e);
                throw new Error('cannot flush/close remote file');
            }
        }
    }
async function writeChunk ( ) { if ( chunks . length > 0 ) { // get first element const l = chunks . shift ( ) ; // increment size counter currentUploadSize += l . length ; // write first element to file try { await _virtualTerminal . executeCommand ( '__nmtwrite("' + l + '")' ) ; } catch ( e ) { _logger . debug ( e ) ; throw new Error ( 'cannot write chunk to remote file' ) ; } // run progress callback progressCb . apply ( progressCb , [ currentUploadSize , absoluteFilesize ] ) ; // write next await writeChunk ( ) ; } else { // ensure that the progress callback is called, even for empty files progressCb . apply ( progressCb , [ currentUploadSize , absoluteFilesize ] ) ; // send file close command try { await _virtualTerminal . executeCommand ( _luaCommandBuilder . command . fileCloseFlush ) ; } catch ( e ) { _logger . debug ( e ) ; throw new Error ( 'cannot flush/close remote file' ) ; } } }
internal helper to write chunks
internal helper to write chunks