toutpt
toutpt

Reputation: 5220

How to extract zip file with gulp

Here is my gulpfile.js

var gulp = require('gulp');
var download = require('gulp-download');
var unzip = require('unzip');

gulp.task('download-selenium', function(){
  download('https://selenium.googlecode.com/files/selenium-server-2.39.0.zip')
    .pipe(unzip.Extract({ path: 'selenium' }))
    .pipe(gulp.dest("selenium"));
});

When I launch it I have the following issue:

$ gulp download-selenium
[gulp] Using file /Users/toutpt/makina/nmd/carteeco/mockup/gulpfile.js
[gulp] Working directory changed to /Users/toutpt/makina/nmd/carteeco/mockup
[gulp] Running 'download-selenium'...
[gulp] Errored 'download-selenium' in 9.08 ms Cannot pipe. Not readable.

/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/index.js:153
            throw err;
                  ^
Error: Cannot pipe. Not readable.
    at Extract.Writable.pipe (_stream_writable.js:125:22)
    at Gulp.gulp.task.server (/Users/toutpt/makina/nmd/carteeco/mockup/gulpfile.js:99:6)
    at module.exports (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:31:7)
    at Gulp.Orchestrator._runTask (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at Gulp.run (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/index.js:20:14)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:132:19
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)

So How could I extract my downloaded file ?

Upvotes: 1

Views: 4211

Answers (2)

Brian Tol
Brian Tol

Reputation: 4199

gulp-download doesn't seem to be maintained anymore, and gulp-gunzip has a more up-to-date example:

var gulp = require('gulp')
var request = require('request')
var source = require('vinyl-source-stream')
var gunzip = require('gulp-gunzip')
var untar = require('gulp-untar')

gulp.task('default', function () {
  return request('http://example.org/some-file.tar.gz')
  .pipe(source('some-file.tar.gz'))
  .pipe(gunzip())
  .pipe(untar())
  .pipe(gulp.dest('output'))
})

Upvotes: 2

SteveLacy
SteveLacy

Reputation: 4162

Remember, gulp uses Streams for the file. npm unzip does not send a pipe-able stream as an output.

For this case you would be best off to not use the gulp.dest, but instead use the unzip extract path.

Try this:

var gulp = require('gulp');
var download = require('gulp-download');
var unzip = require('unzip');

gulp.task('download-selenium', function(){
  download('https://selenium.googlecode.com/files/selenium-server-2.39.0.zip')
    .pipe(unzip.Extract({ path: './selenium' }));
});

Upvotes: 3

Related Questions