Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/api/readable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const assert = require('node:assert')
const { StringDecoder } = require('node:string_decoder')
const { addAbortListener } = require('node:events')
const { Readable } = require('node:stream')
const { RequestAbortedError, NotSupportedError, InvalidArgumentError, AbortError } = require('../core/errors')
Expand Down Expand Up @@ -326,6 +327,9 @@ class BodyReadable extends Readable {
setEncoding (encoding) {
if (Buffer.isEncoding(encoding)) {
this._readableState.encoding = encoding
if (this[kConsume]) {
this[kConsume].decoder = new StringDecoder(encoding)
}
}
return this
}
Expand Down Expand Up @@ -546,8 +550,14 @@ function consumeEnd (consume, encoding) {
* @returns {void}
*/
function consumePush (consume, chunk) {
consume.length += chunk.length
consume.body.push(chunk)
if (consume.decoder) {
const string = consume.decoder.write(chunk)
consume.length += Buffer.byteLength(string)
consume.body.push(string)
} else {
consume.length += chunk.length
consume.body.push(chunk)
}
}

/**
Expand Down
Loading