Erik
Erik

Reputation: 14770

How to download and unzip file via pipelines in gulp?

I'm trying to download and unpack zip archive in gulp by using gulp-decompress. But get an error. My gulp task looks like the following:

var request = require('request');
var decompress = require('gulp-decompress');

gulp.task('unzip', function () {
   request('http://my-server-url/files/report.zip')
      .pipe(decompress())
      .pipe('./uploads')
});

After executing gulp I'm getting the following error:

node_modules\gulp-decompress\index.js:11
                if (file.isNull()) {
                         ^

TypeError: file.isNull is not a function

Upvotes: 3

Views: 1113

Answers (1)

Mark
Mark

Reputation: 181289

I tried it with request and got the same error as you. It probably has to be transformed into a readable or writeable stream (fs.) before continuing in the pipeline which I couldn't get to work without spending too much time.

So let me recommend gulp-download which is much simpler than request.

const gulp = require('gulp');
const download = require("gulp-download");
const decompress = require('gulp-decompress');

const url = 'http://my-server-url/files/report.zip';

gulp.task('unzip', function () {

  download(url)

   .pipe(decompress())
   .pipe(gulp.dest("unzipped"));
});

It's pretty simple. I'm sure others could tell you how to get the module request to work if that is necessary.

Upvotes: 4

Related Questions