@@ -11,6 +11,7 @@ const ProgressBar = require('progress');
1111const { CHUNK_SIZE } = require ( '../lib/constants' ) ;
1212const { generateAuthorization, getRegistryInfo } = require ( '../lib/utils' ) ;
1313const { getExistChunks : _getExistChunks , uploadChunk : _uploadChunk , uploadSuccess : _uploadSuccess } = require ( '../lib/request' ) ;
14+ const BlueBirdPromise = require ( "bluebird" ) ;
1415
1516const argv = require ( '../lib/argv' ) ;
1617const { requestUrl, version } = getRegistryInfo ( argv . registry ) ;
@@ -73,12 +74,15 @@ const upload = async (filePath, parts = []) => {
7374 logger . info ( '开始上传' )
7475
7576 try {
76- for ( let currentChunkIndex = 1 ; currentChunkIndex <= totalChunk ; currentChunkIndex ++ ) {
77+
78+ const chunkIndexs = new Array ( totalChunk ) . fill ( "" ) . map ( ( _ , index ) => index + 1 )
79+
80+ await BlueBirdPromise . map ( chunkIndexs , ( currentChunkIndex ) => {
7781 const start = ( currentChunkIndex - 1 ) * CHUNK_SIZE ;
7882 const end = ( ( start + CHUNK_SIZE ) >= fileSize ) ? fileSize : start + CHUNK_SIZE - 1 ;
7983 const stream = fs . createReadStream ( filePath , { start, end } )
8084 let buf = [ ] ;
81- await new Promise ( ( resolve ) => {
85+ return new Promise ( ( resolve ) => {
8286 stream . on ( 'data' , data => {
8387 buf . push ( data )
8488 } )
@@ -93,7 +97,8 @@ const upload = async (filePath, parts = []) => {
9397 } ) . catch ( error => {
9498 throw Error ( error )
9599 } )
96- }
100+ } , { concurrency : argv . concurrency } )
101+
97102 } catch ( error ) {
98103 logger . error ( error . message ) ;
99104 logger . error ( error . stack ) ;
0 commit comments