Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 10, 2024
1 parent dc3948d commit 644b157
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,8 @@ function _fill(buf, value, offset, end, encoding) {
Buffer.prototype.write = function write(string, offset, length, encoding) {
// Buffer#write(string);
if (offset === undefined) {
// Do nothing
offset = 0;
length = this.length;
// Buffer#write(string, encoding)
} else if (length === undefined && typeof offset === 'string') {
encoding = offset;
Expand All @@ -1108,16 +1109,19 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
}

const len = string.length;
if (len <= 16 && len <= length && (!encoding || encoding === 'ascii' || encoding === 'utf8')) {
if (
len <= 16 &&
len <= length &&
(!encoding || encoding === 'ascii' || encoding === 'utf8')
) {
let n = 0;
let pos = offset ?? 0;
while (true) {
const code = StringPrototypeCharCodeAt(string, n);
const code = string.charCodeAt(n);
if (code >= 128) {
break;
}

this[pos + n] = code;
this[offset + n] = code;
n++;

if (n === len) {
Expand Down

0 comments on commit 644b157

Please sign in to comment.