fix(node): add support for Buffer.from(uint8Array) (#25630)

* fix(Node buffer): add support for `from(buffer)`

* refactor(Node buffer): consolidate overloads of `Buffer.from`
This commit is contained in:
Nico Jansen
2018-05-09 15:11:52 -07:00
committed by Sheetal Nandi
parent e3e32dbd41
commit db27d0733d
2 changed files with 8 additions and 5 deletions
+1 -1
View File
@@ -379,7 +379,7 @@ declare var Buffer: {
* Creates a new Buffer using the passed {data}
* @param data data to create a new Buffer
*/
from(data: any[] | string | Buffer | ArrayBuffer /*| TypedArray*/): Buffer;
from(data: any[] | string | Buffer | ArrayBuffer | Uint8Array /*| TypedArray*/): Buffer;
/**
* Creates a new Buffer containing the given JavaScript string {str}.
* If provided, the {encoding} parameter identifies the character encoding.
+7 -4
View File
@@ -432,10 +432,13 @@ function bufferTests() {
// String
const buf3: Buffer = Buffer.from('this is a tést');
// ArrayBuffer
const arr: Uint16Array = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;
const buf4: Buffer = Buffer.from(arr.buffer);
const arrUint16: Uint16Array = new Uint16Array(2);
arrUint16[0] = 5000;
arrUint16[1] = 4000;
const buf4: Buffer = Buffer.from(arrUint16.buffer);
const arrUint8: Uint8Array = new Uint8Array(2);
const buf5: Buffer = Buffer.from(arrUint8);
const buf6: Buffer = Buffer.from(buf1);
}
// Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])