可能使用gulp创build一个zip文件并上传而不使用临时文件?

我想创build一个zip文件并上传它,而不用像这样写一个临时文件到磁盘:

gulp.task( 'zip-upload', function() { return gulp.src( '**/*', { cwd: 'out/', cwdbase: true } ) .pipe( zip( 'file.zip' ) ) .pipe( request.put( 'https://myurl.com' ) ); }); 

但是它会抛出一个错误:

 http.js:853 throw new TypeError('first argument must be a string or Buffer'); TypeError: first argument must be a string or Buffer at ClientRequest.OutgoingMessage.write (http.js:853:11) at Request.write (.../node_modules/request/request.js:1315:25) 

我用两个任务解决了这个问题,但这并不理想:

 gulp.task( 'zip', function() { return gulp.src( '**/*', { cwd: 'out/', cwdbase: true } ) .pipe( zip( 'file.zip' ) ) .pipe( gulp.dest( './' ) ); }); gulp.task( 'upload', [ 'zip' ], function() { fs.createReadStream('file.zip').pipe( request.put( 'https://myurl.com' ) ); }); 

有没有可能像第一种方法一样使用吞咽?

依赖关系:

 npm install gulp-zip request 

谢谢。

它看起来像gulp缓冲区应该能够解决您的问题:

安装gulp-buffer并将其添加到您的gulp文件中,然后在您的zip压缩请求和请求之间插入缓冲区。

 gulp.task( 'zip-upload', function() { return gulp.src( '**/*', { cwd: 'out/', cwdbase: true } ) .pipe( zip( 'file.zip' ) ) .pipe( buffer() ) .pipe( request.put( 'https://myurl.com' ) ); });