diff --git a/tests/comp_bytes.js b/tests/comp_bytes.js index ab088ecf3..17dacee92 100644 --- a/tests/comp_bytes.js +++ b/tests/comp_bytes.js @@ -1,39 +1,43 @@ var tape = require("tape"); -class CustomBuffer extends Buffer { - static toCustom(b) { - b._isCustom = true; - return b; - } - - static isCustom(b) { - return !!b._isCustom; - } - - static from(...args) { - return CustomBuffer.toCustom(Buffer.from(...args)); - } - - static alloc(...args) { - return CustomBuffer.toCustom(Buffer.alloc(...args)); - } - - static allocUnsafe(...args) { - return CustomBuffer.toCustom(Buffer.allocUnsafe(...args)); - } - - static allocUnsafeSlow(...args) { - return CustomBuffer.toCustom(Buffer.allocUnsafeSlow(...args)); - } - - slice(...args) { - return CustomBuffer.toCustom(super.slice(...args)); - } +var protobuf = require(".."); + +// extends Buffer +(CustomBuffer.prototype = Object.create(Buffer.prototype)).constructor = CustomBuffer; + +function CustomBuffer() { + Buffer.call(this); +} + +CustomBuffer.isBuffer = Buffer.isBuffer.bind(Buffer); + +CustomBuffer.toCustom = function (b) { + b._isCustom = true; + return b; +} + +CustomBuffer.isCustom = function (b) { + return !!b._isCustom; +} + +CustomBuffer.from = function (...args) { + return CustomBuffer.toCustom(Buffer.from(...args)); +} + +CustomBuffer.allow = function (...args) { + return CustomBuffer.toCustom(Buffer.alloc(...args)); +} + +CustomBuffer.allocUnsafe = function (...args) { + return CustomBuffer.toCustom(Buffer.allocUnsafe(...args)); +} + +CustomBuffer.prototype.slice = function (...args) { + return CustomBuffer.toCustom(this.slice(...args)); } tape.test("configure a custom encoder/decoder for bytes", function(test) { - var protobuf = require(".."); var oldBuffer = protobuf.util.Buffer; protobuf.util.Buffer = CustomBuffer;