Updating write* methods to return offsets, fill to return the Buffer, and making isBuffer a type guard.

This commit is contained in:
John Vilk
2015-10-08 02:50:40 -04:00
parent 66f88ec518
commit 7fc487562c
2 changed files with 36 additions and 17 deletions
+20 -1
View File
@@ -34,7 +34,7 @@ assert.doesNotThrow(() => {
fs.writeFile("thebible.txt",
"Do unto others as you would have them do unto you.",
assert.ifError);
fs.write(1234, "test");
fs.writeFile("Harry Potter",
@@ -87,6 +87,25 @@ function bufferTests() {
console.log(Buffer.byteLength('xyz123', 'ascii'));
var result1 = Buffer.concat([utf8Buffer, base64Buffer]);
var result2 = Buffer.concat([utf8Buffer, base64Buffer], 9999999);
// Test that TS 1.6 works with the 'as Buffer' annotation
// on isBuffer.
var a: Buffer | number;
a = new Buffer(10);
if (Buffer.isBuffer(a)) {
a.writeUInt8(3, 4);
}
// write* methods return offsets.
var b = new Buffer(16);
var result: number = b.writeUInt32LE(0, 0);
result = b.writeUInt16LE(0, 4);
result = b.writeUInt8(0, 6);
result = b.writeInt8(0, 7);
result = b.writeDoubleLE(0, 8);
// fill returns the input buffer.
b.fill('a').fill('b');
}