mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
fix(fetch): fixed ReferenceError issue when TextEncoder is not available in the environment; (#6410)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
|
||||
export const streamChunk = function* (chunk, chunkSize) {
|
||||
let len = chunk.byteLength;
|
||||
|
||||
@@ -17,16 +18,14 @@ export const streamChunk = function* (chunk, chunkSize) {
|
||||
}
|
||||
}
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
export const readBytes = async function* (iterable, chunkSize) {
|
||||
export const readBytes = async function* (iterable, chunkSize, encode) {
|
||||
for await (const chunk of iterable) {
|
||||
yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encoder.encode(String(chunk))), chunkSize);
|
||||
yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
|
||||
}
|
||||
}
|
||||
|
||||
export const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
||||
const iterator = readBytes(stream, chunkSize);
|
||||
export const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
||||
const iterator = readBytes(stream, chunkSize, encode);
|
||||
|
||||
let bytes = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user