mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
[node] Add Buffer.poolSize() and correct Buffer.byteLength() (#20419)
* [node] Add Buffer.poolSize * [node] Allow more types for Buffer.byteLength() * fix lint issue
This commit is contained in:
8
types/node/index.d.ts
vendored
8
types/node/index.d.ts
vendored
@@ -239,10 +239,10 @@ declare var Buffer: {
|
||||
* Gives the actual byte length of a string. encoding defaults to 'utf8'.
|
||||
* This is not the same as String.prototype.length since that returns the number of characters in a string.
|
||||
*
|
||||
* @param string string to test.
|
||||
* @param string string to test. (TypedArray is also allowed, but it is only available starting ES2017)
|
||||
* @param encoding encoding used to evaluate (defaults to 'utf8')
|
||||
*/
|
||||
byteLength(string: string, encoding?: string): number;
|
||||
byteLength(string: string | Buffer | DataView | ArrayBuffer, encoding?: string): number;
|
||||
/**
|
||||
* Returns a buffer which is the result of concatenating all the buffers in the list together.
|
||||
*
|
||||
@@ -282,6 +282,10 @@ declare var Buffer: {
|
||||
* @param size count of octets to allocate
|
||||
*/
|
||||
allocUnsafeSlow(size: number): Buffer;
|
||||
/**
|
||||
* This is the number of bytes used to determine the size of pre-allocated, internal Buffer instances used for pooling. This value may be modified.
|
||||
*/
|
||||
poolSize: number;
|
||||
};
|
||||
|
||||
/************************************************
|
||||
|
||||
@@ -396,6 +396,32 @@ function bufferTests() {
|
||||
const buf2: Buffer = Buffer.from('7468697320697320612074c3a97374', 'hex');
|
||||
}
|
||||
|
||||
// Class Method byteLenght
|
||||
{
|
||||
let len: number;
|
||||
len = Buffer.byteLength("foo");
|
||||
len = Buffer.byteLength("foo", "utf8");
|
||||
|
||||
const b = Buffer.from("bar");
|
||||
len = Buffer.byteLength(b);
|
||||
len = Buffer.byteLength(b, "utf16le");
|
||||
|
||||
const ab = new ArrayBuffer(15);
|
||||
len = Buffer.byteLength(ab);
|
||||
len = Buffer.byteLength(ab, "ascii");
|
||||
|
||||
const dv = new DataView(ab);
|
||||
len = Buffer.byteLength(dv);
|
||||
len = Buffer.byteLength(dv, "utf16le");
|
||||
}
|
||||
|
||||
// Class Method poolSize
|
||||
{
|
||||
let s: number;
|
||||
s = Buffer.poolSize;
|
||||
Buffer.poolSize = 4096;
|
||||
}
|
||||
|
||||
// Test that TS 1.6 works with the 'as Buffer' annotation
|
||||
// on isBuffer.
|
||||
var a: Buffer | number;
|
||||
|
||||
Reference in New Issue
Block a user