Skip to content

Commit 5506f99

Browse files
committed
map charsWritten to fast buffer
1 parent ececd92 commit 5506f99

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

lib/buffer.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,23 +211,33 @@ Buffer.prototype.write = function write (string, offset, encoding) {
211211
// Make sure we are not going to overflow
212212
var maxLength = this.length - offset;
213213

214+
var ret;
214215
switch (encoding) {
215216
case 'utf8':
216217
case 'utf-8':
217-
return this.parent.utf8Write(string, this.offset + offset, maxLength);
218+
ret = this.parent.utf8Write(string, this.offset + offset, maxLength);
219+
break;
218220

219221
case 'ascii':
220-
return this.parent.asciiWrite(string, this.offset + offset, maxLength);
222+
ret = this.parent.asciiWrite(string, this.offset + offset, maxLength);
223+
break;
221224

222225
case 'binary':
223-
return this.parent.binaryWrite(string, this.offset + offset, maxLength);
226+
ret = this.parent.binaryWrite(string, this.offset + offset, maxLength);
227+
break;
224228

225229
case 'base64':
226-
return this.parent.base64Write(string, this.offset + offset, maxLength);
230+
// Warning: maxLength not taken into account in base64Write
231+
ret = this.parent.base64Write(string, this.offset + offset, maxLength);
232+
break;
227233

228234
default:
229235
throw new Error('Unknown encoding');
230236
}
237+
238+
Buffer._charsWritten = SlowBuffer._charsWritten;
239+
240+
return ret;
231241
};
232242

233243

0 commit comments

Comments
 (0)