'optimize' : function (opts) { var options = clone (config) opts = opts || {}; // Set config optiosn to use for this current optimization session assign (options, opts) if (options.status) { console.log (chalk.yellow.bgBlack ('Starting image optimization ... this may take a while.')) } return through.obj (function (file, enc, cb) { stream = this // If file is null continue if (file.isNull ()) { cb (null, file) return } // Add file to batch batchFiles.push (file) if (batchFiles.length >= options.batchSize) { batchOptimize (batchFiles, options, function (files) { pushFiles (files) batchFiles = [] cb () }) } else { cb () } }, function (cb) { batchOptimize (batchFiles, options, function (files) { pushFiles (files) batchFiles = [] if (options.status) { console.log (chalk.green.bgBlack ('Optimization complete!')) } cb () }) }) }