summaryrefslogtreecommitdiff
path: root/node_modules/gather-stream/index.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:58:02 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:58:02 +0800
commitfee47f6414cc3ae9a88f3ee0ed20f1d6f2d9f556 (patch)
tree2b99dd57fc676a3819ef3cc46ac43df0043c2bb3 /node_modules/gather-stream/index.js
parent0379526e20e1ff212df23e6326741aa9c06df204 (diff)
added plugin from postcss: postcss-fixes rucksack-css
Diffstat (limited to 'node_modules/gather-stream/index.js')
-rw-r--r--node_modules/gather-stream/index.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/node_modules/gather-stream/index.js b/node_modules/gather-stream/index.js
new file mode 100644
index 00000000..cab8bda9
--- /dev/null
+++ b/node_modules/gather-stream/index.js
@@ -0,0 +1,44 @@
+var Writable = require('stream').Writable,
+ util = require('util');
+
+function Gatherer(opts) {
+ opts.decodeStrings = true;
+ Writable.call(this, opts);
+ this._length = 0;
+ this._chunks = [];
+ this._maxLength = ('maxLength' in opts) ? opts.maxLength : Infinity;
+}
+
+util.inherits(Gatherer, Writable);
+
+Gatherer.prototype._write = function (d, _enc, cb) {
+ if (this._length + d.length > this._maxLength) {
+ return cb(new Error("Maximum length exceeded!"));
+ }
+ this._chunks.push(d);
+ this._length += d.length;
+ cb();
+}
+
+Gatherer.prototype.getBuffer = function () {
+ return Buffer.concat(this._chunks, this._length);
+}
+
+module.exports = function (opts, cb) {
+ if (typeof opts === 'function') {
+ cb = opts;
+ opts = {};
+ }
+ var target = new Gatherer(opts);
+ target.on('error', cb);
+ target.on('pipe', function (source) {
+ source.on('error', cb);
+ });
+ target.on('unpipe', function (source) {
+ source.removeListener('error', cb);
+ });
+ target.on('finish', function () {
+ cb(null, target.getBuffer());
+ });
+ return target;
+}