Skip to content

Commit

Permalink
fixes Buffer polyfill Buffer#write method behaviour (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegDokuka committed Dec 3, 2019
1 parent 709aacf commit 188ed68
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions packages/rsocket-core/src/LiteBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,37 @@ function utf8Write(

Buffer.prototype.write = function write(
input: string,
offset: number,
length: number,
encoding: 'utf8',
offset?: number,
length?: number,
encoding?: 'utf8',
) {
if (offset === undefined) {
encoding = 'utf8';
length = this.length;
offset = 0;
// Buffer#write(string, encoding)
} else if (length === undefined && typeof offset === 'string') {
encoding = offset;
length = this.length;
offset = 0;
// Buffer#write(string, offset[, length][, encoding])
} else if (isFinite(offset)) {
offset = offset >>> 0;
if (length === undefined) {
encoding = 'utf8';
length = this.length;
} else if (isFinite(length)) {
length = length >>> 0;
if (encoding === undefined) encoding = 'utf8';
} else {
encoding = length;
length = this.length;
}
} else {
throw new Error(
'Buffer.write(string, encoding, offset[, length]) is no longer supported',
);
}
switch (encoding) {
case 'utf8':
return utf8Write(this, input, offset, length);
Expand Down

0 comments on commit 188ed68

Please sign in to comment.