Skip to content

Commit

Permalink
Revert "Removed mention of Buffer in byteSourceToUint8Array"
Browse files Browse the repository at this point in the history
This reverts commit f00e06c.

Although Node Buffers are not covered by the tests, it seems that there
are users relying on them, so we need to add back in support for them.

This fixes issue protocolbuffers#4359.
  • Loading branch information
acozzette committed Mar 9, 2018
1 parent 8e44a86 commit f8005a5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions js/binary/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,10 @@ jspb.utils.byteSourceToUint8Array = function(data) {
return /** @type {!Uint8Array} */(new Uint8Array(data));
}

if (data.constructor === Buffer) {
return /** @type {!Uint8Array} */(new Uint8Array(data));
}

if (data.constructor === Array) {
data = /** @type {!Array<number>} */(data);
return /** @type {!Uint8Array} */(new Uint8Array(data));
Expand Down

0 comments on commit f8005a5

Please sign in to comment.