Framework updates
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
66
node_modules/axios/lib/helpers/trackStream.js
generated
vendored
66
node_modules/axios/lib/helpers/trackStream.js
generated
vendored
@@ -1,4 +1,3 @@
|
||||
|
||||
export const streamChunk = function* (chunk, chunkSize) {
|
||||
let len = chunk.byteLength;
|
||||
|
||||
@@ -15,13 +14,13 @@ export const streamChunk = function* (chunk, chunkSize) {
|
||||
yield chunk.slice(pos, end);
|
||||
pos = end;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const readBytes = async function* (iterable, chunkSize) {
|
||||
for await (const chunk of readStream(iterable)) {
|
||||
yield* streamChunk(chunk, chunkSize);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const readStream = async function* (stream) {
|
||||
if (stream[Symbol.asyncIterator]) {
|
||||
@@ -32,7 +31,7 @@ const readStream = async function* (stream) {
|
||||
const reader = stream.getReader();
|
||||
try {
|
||||
for (;;) {
|
||||
const {done, value} = await reader.read();
|
||||
const { done, value } = await reader.read();
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
@@ -41,7 +40,7 @@ const readStream = async function* (stream) {
|
||||
} finally {
|
||||
await reader.cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
||||
const iterator = readBytes(stream, chunkSize);
|
||||
@@ -53,35 +52,38 @@ export const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
||||
done = true;
|
||||
onFinish && onFinish(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return new ReadableStream({
|
||||
async pull(controller) {
|
||||
try {
|
||||
const {done, value} = await iterator.next();
|
||||
return new ReadableStream(
|
||||
{
|
||||
async pull(controller) {
|
||||
try {
|
||||
const { done, value } = await iterator.next();
|
||||
|
||||
if (done) {
|
||||
_onFinish();
|
||||
controller.close();
|
||||
return;
|
||||
if (done) {
|
||||
_onFinish();
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
if (onProgress) {
|
||||
let loadedBytes = (bytes += len);
|
||||
onProgress(loadedBytes);
|
||||
}
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
} catch (err) {
|
||||
_onFinish(err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
if (onProgress) {
|
||||
let loadedBytes = bytes += len;
|
||||
onProgress(loadedBytes);
|
||||
}
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
} catch (err) {
|
||||
_onFinish(err);
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
cancel(reason) {
|
||||
_onFinish(reason);
|
||||
return iterator.return();
|
||||
},
|
||||
},
|
||||
cancel(reason) {
|
||||
_onFinish(reason);
|
||||
return iterator.return();
|
||||
{
|
||||
highWaterMark: 2,
|
||||
}
|
||||
}, {
|
||||
highWaterMark: 2
|
||||
})
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user