aboutsummaryrefslogtreecommitdiff
path: root/node_modules/gulp-gzip/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/gulp-gzip/lib')
-rwxr-xr-xnode_modules/gulp-gzip/lib/compress.js88
-rwxr-xr-xnode_modules/gulp-gzip/lib/utils.js43
2 files changed, 0 insertions, 131 deletions
diff --git a/node_modules/gulp-gzip/lib/compress.js b/node_modules/gulp-gzip/lib/compress.js
deleted file mode 100755
index db04c4c23..000000000
--- a/node_modules/gulp-gzip/lib/compress.js
+++ /dev/null
@@ -1,88 +0,0 @@
-var zlib = require('zlib');
-var Readable = require('stream').Readable;
-var toArray = require('stream-to-array');
-
-function convertContentsToBuffer(contents, callback) {
- if (contents instanceof Buffer) {
- callback(null, contents);
- } else {
- toArray(contents, function (err, chunks) {
- if (err) {
- callback(err, null);
- return;
- }
-
- callback(null, Buffer.concat(chunks));
- });
- }
-}
-
-function convertContentsToStream(contents, callback) {
- if (contents instanceof Readable) {
- callback(null, contents);
- } else {
- var rs = new Readable({ objectMode: true });
- rs._read = function() {
- rs.push(contents);
- rs.push(null);
- };
- callback(null, rs);
- }
-}
-
-module.exports = function(originalContents, options, callback) {
-
- convertContentsToBuffer(originalContents, function(err, contentsAsBuffer) {
- if (err) {
- callback(err, null, false);
- return;
- }
-
- var originalContentLength = contentsAsBuffer.length;
-
- // Check if the threshold option is set
- // If true, check if the buffer length is greater than the threshold
- if (options.threshold && originalContentLength < options.threshold) {
- // File size is smaller than the threshold
- // Pass it along to the next plugin without compressing
- if (originalContents instanceof Buffer) {
- callback(null, contentsAsBuffer, false);
- } else {
- convertContentsToStream(contentsAsBuffer, function(err, contentsAsStream) {
- callback(null, contentsAsStream, false);
- });
- }
- return;
- }
-
- convertContentsToStream(contentsAsBuffer, function(err, contentsAsStream) {
- if (err) {
- callback(err, null, false);
- return;
- }
-
- // Compress the contents
- var gzipStream = zlib.createGzip(options.gzipOptions);
- contentsAsStream.pipe(gzipStream);
-
- convertContentsToBuffer(gzipStream, function(err, compressedContentsAsBuffer) {
- if (err) {
- callback(err, null, false);
- return;
- }
-
- if (options.skipGrowingFiles && compressedContentsAsBuffer.length >= originalContentLength) {
- callback(null, originalContents, false);
- } else {
- if (originalContents instanceof Buffer) {
- callback(null, compressedContentsAsBuffer, true);
- } else {
- convertContentsToStream(compressedContentsAsBuffer, function(err, compressedContentsStream) {
- callback(null, compressedContentsStream, true);
- });
- }
- }
- });
- });
- });
-};
diff --git a/node_modules/gulp-gzip/lib/utils.js b/node_modules/gulp-gzip/lib/utils.js
deleted file mode 100755
index 5658e1ca1..000000000
--- a/node_modules/gulp-gzip/lib/utils.js
+++ /dev/null
@@ -1,43 +0,0 @@
-var bytes = require('bytes');
-
-// Merge source object with target object while handling threshold option
-// Used to merge user defined plugin options with default options
-function merge(target, source) {
- if (typeof source === 'undefined') source = {};
-
- Object.keys(source).forEach(function(key) {
- if (key === 'threshold') {
- target[key] = threshold(source[key]);
- } else {
- target[key] = source[key];
- }
- });
-
- return target;
-}
-
-// Parse the threshold plugin option
-// Specifies the minimum file size that will be compressed
-// Can be a string, number, or boolean
-function threshold(obj) {
- var ret;
-
- switch (typeof obj) {
- case 'string':
- ret = bytes(obj) < 150 ? 150 : bytes(obj);
- break;
- case 'number':
- ret = obj < 150 ? 150 : obj;
- break;
- case 'boolean':
- ret = obj === false ? false : 150;
- break;
- default:
- throw new Error('threshold must be String|Number|Boolean');
- }
-
- return ret;
-}
-
-exports.merge = merge;
-exports.threshold = threshold;