From: Feross Aboukhadijeh Date: Mon, 25 Nov 2013 09:16:16 +0000 (-0800) Subject: make toJSON() use node 0.12 behavior; make test reliable X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=914cdf7456a1e1359bb6d186c3d85be0f7a7d108;p=buffer.git make toJSON() use node 0.12 behavior; make test reliable --- diff --git a/index.js b/index.js index dca0103..5426938 100644 --- a/index.js +++ b/index.js @@ -264,7 +264,10 @@ function BufferToString (encoding, start, end) { } function BufferToJSON () { - return Array.prototype.slice.call(this, 0) + return { + type: 'Buffer', + data: Array.prototype.slice.call(this, 0) + } } // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) diff --git a/test/basic.js b/test/basic.js index f53e7fc..8075b61 100644 --- a/test/basic.js +++ b/test/basic.js @@ -38,7 +38,7 @@ test('buffer toJSON()', function (t) { var data = [1, 2, 3, 4] t.deepEqual( new B(data).toJSON(), - new Buffer(data).toJSON() + { type: 'Buffer', data: [1,2,3,4] } ) t.end() })