avancement planning

This commit is contained in:
2026-05-26 11:58:39 +02:00
parent 619a2b240a
commit 150b97cd2e
4892 changed files with 99214 additions and 429382 deletions
+25 -15
View File
@@ -1,15 +1,15 @@
'use strict'
const { Minipass } = require('minipass')
const MinipassSized = require('minipass-sized')
const { MinipassSized } = require('minipass-sized')
const Blob = require('./blob.js')
const { BUFFER } = Blob
const FetchError = require('./fetch-error.js')
// optional dependency on 'encoding'
let convert
// optional dependency on 'iconv-lite'
let decode
try {
convert = require('encoding').convert
decode = require('iconv-lite').decode
} catch (e) {
// defer error until textConverted is called
}
@@ -92,6 +92,10 @@ class Body {
}
textConverted () {
/* istanbul ignore if */
if (typeof decode !== 'function') {
throw new Error('The package `iconv-lite` must be installed to use the textConverted() function')
}
return this[CONSUME_BODY]().then(buf => convertBody(buf, this.headers))
}
@@ -285,11 +289,6 @@ const isBlob = obj =>
/^(Blob|File)$/.test(obj[Symbol.toStringTag])
const convertBody = (buffer, headers) => {
/* istanbul ignore if */
if (typeof convert !== 'function') {
throw new Error('The package `encoding` must be installed to use the textConverted() function')
}
const ct = headers && headers.get('content-type')
let charset = 'utf-8'
let res
@@ -339,12 +338,23 @@ const convertBody = (buffer, headers) => {
}
}
// turn raw buffers into a single utf-8 buffer
return convert(
buffer,
'UTF-8',
charset
).toString()
if (charset === 'UTF-8') {
return buffer.toString('UTF-8')
}
charset = charset.toString().trim()
.replace(/^latin[-_]?(\d+)$/i, 'ISO-8859-$1')
.replace(/^win(?:dows)?[-_]?(\d+)$/i, 'WINDOWS-$1')
.replace(/^utf[-_]?(\d+)$/i, 'UTF-$1')
.replace(/^ks_c_5601-1987$/i, 'CP949')
.replace(/^us[-_]?ascii$/i, 'ASCII')
.toUpperCase()
try {
return decode(buffer, charset).toString()
} catch {
/* istanbul ignore next */
return buffer.toString('UTF-8')
}
}
module.exports = Body