我想创建一个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
谢谢.