Skip to content

Commit

Permalink
Fixed tests for node 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchoz49 committed Jun 24, 2019
1 parent a87a83a commit 681dc13
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions tests/comp_bytes.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 681dc13

Please sign in to comment.