'use strict';
const gutil = require('gulp-util');
const through = require('through2');
const meta = require('jsforce-metadata-tools');
const decompress = require('decompress');

let extractZipContents = (zipFileContent, dirMapping, logger, verbose) => {
  logger.log('');
  const zipBuffer = Buffer.from(zipFileContent, 'base64');
  return decompress(zipBuffer, dirMapping);
}

module.exports = options => {
  return through.obj((file, enc, callback) => {
    let err;
    if (file.isNull()) {
      return callback(null, file);
    }
    if (file.isStream()) {
      err = new gutil.PluginError('gulp-jsforce-retrieve', 'Stream input is not supported');
      return callback(err);
    }
    options.logger = gutil;
    meta.retrieveByPackageXML(options.src + '/package.xml', options)
    .then(res => {
      meta.reportRetrieveResult(res, gutil, options.verbose);
      if (!res.success) {
        return callback(new Error('Deploy Failed.'),file);
      }
      extractZipContents(res.zipFile, options.src, gutil, options.verbose)
      delete res.zipFile;
      file.contents = new Buffer.from(JSON.stringify(res));
      callback(null, file);
    })
    .catch(err => {
      gutil.log('gulp-jsforce-retrieve',err.message)
      callback(err);
    });
  });
};
@@ -171,16 +171,62 @@
 ess');%0A%0A
+const PLUGIN_NAME = 'gulp-jsforce-retrieve';%0A%0A
 let extr
@@ -611,14 +611,24 @@
     
-err = 
+return callback(
 new 
@@ -645,39 +645,27 @@
 inError(
-'gulp-jsforce-retrieve'
+PLUGIN_NAME
 , 'Strea
@@ -694,35 +694,8 @@
 ed')
-;%0A      return callback(err
 );%0A 
@@ -935,29 +935,55 @@
 new 
-Error('Deploy F
+gutil.PluginError(PLUGIN_NAME, 'Retrieve f
 ailed
-.
 '),f
@@ -1228,39 +1228,27 @@
 til.log(
-'gulp-jsforce-retrieve'
+PLUGIN_NAME
 ,err.mes

Use plugin name definition