diff --git a/lib/vendor/buffer/buffer.js b/lib/vendor/buffer/buffer.js index bbe05078..41ea6da8 100644 --- a/lib/vendor/buffer/buffer.js +++ b/lib/vendor/buffer/buffer.js @@ -1,57 +1,10 @@ -function SpecificBuffer (_Buffer) { - const Buffer = function () { - if (typeof arguments[0] === 'number') { - return _Buffer.alloc(...arguments); - } - - return _Buffer.from(...arguments); - } - - Buffer.poolSize = _Buffer.poolSize; - - Object.defineProperty(Buffer, Symbol.hasInstance, { - value: function (instance) { - return instance instanceof _Buffer; - } - }); - - Buffer.isBuffer = function () { - return _Buffer.isBuffer(...arguments); - } - - Buffer.alloc = function () { - return _Buffer.alloc(...arguments); - } - - Buffer.allocUnsafe = function () { - return _Buffer.allocUnsafe(...arguments); - } - - Buffer.allocUnsafeSlow = function () { - return _Buffer.allocUnsafeSlow(...arguments); +function getBufferModule (buffer) { + return { + Buffer: buffer.Buffer, + SlowBuffer: buffer.SlowBuffer, + INSPECT_MAX_BYTES: buffer.INSPECT_MAX_BYTES, + kMaxLength: buffer.kMaxLength } - - Buffer.from = function () { - return _Buffer.from(...arguments); - } - - Buffer.compare = function () { - return _Buffer.compare(...arguments); - } - - Buffer.isEncoding = function () { - return _Buffer.isEncoding(...arguments); - } - - Buffer.concat = function () { - return _Buffer.concat(...arguments); - } - - Buffer.byteLength = function () { - return _Buffer.byteLength(...arguments); - } - - return Buffer; } -module.exports = SpecificBuffer; +module.exports = getBufferModule; diff --git a/lib/vendor/buffer/index.browser.js b/lib/vendor/buffer/index.browser.js index 96f052b5..f07c967a 100644 --- a/lib/vendor/buffer/index.browser.js +++ b/lib/vendor/buffer/index.browser.js @@ -1,9 +1,8 @@ -const SpecificBuffer = require('./buffer'); +const getBufferModule = require('./buffer'); +const SpecificBuffer = require('./specific-buffer'); const buffer = require('buffer/'); -module.exports = { - Buffer: SpecificBuffer(buffer.Buffer), - SlowBuffer: buffer.SlowBuffer, - INSPECT_MAX_BYTES: buffer.INSPECT_MAX_BYTES, - kMaxLength: buffer.kMaxLength -} +module.exports = getBufferModule({ + ...buffer, + Buffer: SpecificBuffer(buffer.Buffer) +}) diff --git a/lib/vendor/buffer/index.js b/lib/vendor/buffer/index.js index eed3ce6e..9accc807 100644 --- a/lib/vendor/buffer/index.js +++ b/lib/vendor/buffer/index.js @@ -1,9 +1,8 @@ -const SpecificBuffer = require('./buffer'); +const getBufferModule = require('./buffer'); +const SpecificBuffer = require('./specific-buffer'); const buffer = globalThis._nodeRequires.buffer; -module.exports = { +module.exports = getBufferModule({ + ...buffer, Buffer: SpecificBuffer(globalThis.Buffer), - SlowBuffer: buffer.SlowBuffer, - INSPECT_MAX_BYTES: buffer.INSPECT_MAX_BYTES, - kMaxLength: buffer.kMaxLength -} +}); diff --git a/lib/vendor/buffer/specific-buffer.js b/lib/vendor/buffer/specific-buffer.js new file mode 100644 index 00000000..d2968066 --- /dev/null +++ b/lib/vendor/buffer/specific-buffer.js @@ -0,0 +1,57 @@ +function SpecificBuffer (_Buffer) { + const Buffer = function () { + if (typeof arguments[0] === 'number') { + return _Buffer.alloc(...arguments); + } + + return _Buffer.from(...arguments); + } + + Buffer.poolSize = _Buffer.poolSize; + + Object.defineProperty(Buffer, Symbol.hasInstance, { + value: function (instance) { + return instance instanceof _Buffer; + } + }); + + Buffer.isBuffer = function () { + return _Buffer.isBuffer(...arguments); + }; + + Buffer.alloc = function () { + return _Buffer.alloc(...arguments); + }; + + Buffer.allocUnsafe = function () { + return _Buffer.allocUnsafe(...arguments); + }; + + Buffer.allocUnsafeSlow = function () { + return _Buffer.allocUnsafeSlow(...arguments); + }; + + Buffer.from = function () { + return _Buffer.from(...arguments); + }; + + Buffer.compare = function () { + return _Buffer.compare(...arguments); + }; + + Buffer.isEncoding = function () { + return _Buffer.isEncoding(...arguments); + }; + + Buffer.concat = function () { + return _Buffer.concat(...arguments); + }; + + Buffer.byteLength = function () { + return _Buffer.byteLength(...arguments); + }; + + return Buffer; +} + +module.exports = SpecificBuffer;