mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
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:
committed by
Sheetal Nandi
parent
e3e32dbd41
commit
db27d0733d
Vendored
+1
-1
@@ -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.
|
||||
|
||||
@@ -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]])
|
||||
|
||||
Reference in New Issue
Block a user