fix: allow Uint8Array and Array<number> where Buffer is accepted
This commit is contained in:
committed by
Michael Vines
parent
6ba2f1d524
commit
6a7115b8bd
11
web3.js/src/util/to-buffer.js
Normal file
11
web3.js/src/util/to-buffer.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// @flow
|
||||
|
||||
export const toBuffer = (arr: Buffer | Uint8Array | Array<number>): Buffer => {
|
||||
if (arr instanceof Buffer) {
|
||||
return arr;
|
||||
} else if (arr instanceof Uint8Array) {
|
||||
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
||||
} else {
|
||||
return Buffer.from(arr);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user