Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

possible to use gulp to create a zip file and upload without using temporary file?

I wanted to create a zip file and upload it without writing a temporary file to disk like so:

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

But it throws an error:

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)

I ended up solving it by using two tasks, but this is not ideal:

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' ) );
});

Is it possible to use something like the first approach with gulp?

Dependencies:

npm install gulp-zip request

Thanks.

like image 587
dimensia Avatar asked Nov 10 '22 08:11

dimensia


1 Answers

It looks like gulp-buffer should be able to fix your issue:

Install gulp-buffer and add it to your gulpfile, after that insert the buffer between your zip call and the request.

gulp.task( 'zip-upload', function() {
  return gulp.src( '**/*', { cwd: 'out/', cwdbase: true } )
    .pipe( zip( 'file.zip' ) )
    .pipe( buffer() )
    .pipe( request.put( 'https://myurl.com' ) );
});
like image 155
Simon Groenewolt Avatar answered Nov 14 '22 21:11

Simon Groenewolt