UNPKG

images-set-to-webp-converter

Version:

Powerful util for images (.png | .jpeg | .jpg) set conversion to .webp, generated by Abobe Images Processor Pro plugin

76 lines (66 loc) 1.89 kB
// Generated by CoffeeScript 1.12.7 var When, Wrapper, mixin, spawn; When = require('when'); spawn = require('child_process').spawn; mixin = require('./utils').mixin; module.exports = Wrapper = (function() { mixin(Wrapper, require('./args')); mixin(Wrapper, require('./io')); function Wrapper(source, bin) { this._args = { _: [] }; this.source = source; this.bin = bin || this.constructor.bin; } Wrapper.prototype._spawn = function(args, stdin, stdout) { var onClose, onErrData, onError, proc, promise, ref, reject, res, resolve, stderr, stdio; if (stdin == null) { stdin = false; } if (stdout == null) { stdout = false; } ref = When.defer(), resolve = ref.resolve, reject = ref.reject, promise = ref.promise; stderr = ''; stdio = [stdin ? 'pipe' : 'ignore', stdout ? 'pipe' : 'ignore', 'pipe']; proc = spawn(this.bin, args, { stdio: stdio }); proc.once('error', onError = function(err) { if ((err.code !== 'OK' || 'OK' !== err.errno)) { return reject(err); } }); proc.once('close', onClose = function(code, signal) { var err; if (code !== 0 || signal !== null) { err = new Error("Command failed: " + stderr); err.code = code; err.signal = signal; return reject(err); } else { return resolve(); } }); proc.stderr.on('data', onErrData = function(data) { return stderr += data; }); promise = promise.ensure(function() { proc.removeListener('error', onError); proc.removeListener('close', onClose); return proc.stderr.removeListener('data', onErrData); }); res = { promise: promise }; if (stdin) { res.stdin = proc.stdin; } if (stdout) { res.stdout = proc.stdout; } return res; }; return Wrapper; })();