Skip to content

Commit 644b157

Browse files
committed
fixup
1 parent dc3948d commit 644b157

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/buffer.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,8 @@ function _fill(buf, value, offset, end, encoding) {
10821082
Buffer.prototype.write = function write(string, offset, length, encoding) {
10831083
// Buffer#write(string);
10841084
if (offset === undefined) {
1085-
// Do nothing
1085+
offset = 0;
1086+
length = this.length;
10861087
// Buffer#write(string, encoding)
10871088
} else if (length === undefined && typeof offset === 'string') {
10881089
encoding = offset;
@@ -1108,16 +1109,19 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
11081109
}
11091110

11101111
const len = string.length;
1111-
if (len <= 16 && len <= length && (!encoding || encoding === 'ascii' || encoding === 'utf8')) {
1112+
if (
1113+
len <= 16 &&
1114+
len <= length &&
1115+
(!encoding || encoding === 'ascii' || encoding === 'utf8')
1116+
) {
11121117
let n = 0;
1113-
let pos = offset ?? 0;
11141118
while (true) {
1115-
const code = StringPrototypeCharCodeAt(string, n);
1119+
const code = string.charCodeAt(n);
11161120
if (code >= 128) {
11171121
break;
11181122
}
11191123

1120-
this[pos + n] = code;
1124+
this[offset + n] = code;
11211125
n++;
11221126

11231127
if (n === len) {

0 commit comments

Comments
 (0)