From 0e96a08490061d9ff27e652f44e739b41ae6dcef Mon Sep 17 00:00:00 2001 From: yuyaryshev Date: Mon, 24 Aug 2020 09:21:52 +0300 Subject: [PATCH] Added join function Added join function defragments BufferList items into one big buffer. --- BufferList.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BufferList.js b/BufferList.js index 6dad448..c063538 100644 --- a/BufferList.js +++ b/BufferList.js @@ -75,6 +75,13 @@ BufferList.prototype.slice = function slice (start, end) { return this.copy(null, 0, start, end) } +BufferList.prototype.join = function join() { + if(this._bufs.length > 1) { + this._bufs[0] = this.copy(null, 0, 0, this.length); + this._bufs.length = 1; + } +} + BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) { if (typeof srcStart !== 'number' || srcStart < 0) { srcStart = 0