我希望创建一个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谢谢。
发布于 2014-07-08 12:46:41
看起来吞咽缓冲器应该能够解决您的问题:
安装gulp缓冲区并将其添加到您的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' ) );
});https://stackoverflow.com/questions/23446290
复制相似问题