Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[node] Add Buffer.poolSize() and correct Buffer.byteLength() #20419

Merged
6 commits merged into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions types/node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,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.
*
Expand Down Expand Up @@ -283,6 +283,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;
};

/************************************************
Expand Down
26 changes: 26 additions & 0 deletions types/node/node-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down