Framework updates
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
61
node_modules/axios/lib/helpers/AxiosTransformStream.js
generated
vendored
61
node_modules/axios/lib/helpers/AxiosTransformStream.js
generated
vendored
@@ -5,24 +5,29 @@ import utils from '../utils.js';
|
||||
|
||||
const kInternals = Symbol('internals');
|
||||
|
||||
class AxiosTransformStream extends stream.Transform{
|
||||
class AxiosTransformStream extends stream.Transform {
|
||||
constructor(options) {
|
||||
options = utils.toFlatObject(options, {
|
||||
maxRate: 0,
|
||||
chunkSize: 64 * 1024,
|
||||
minChunkSize: 100,
|
||||
timeWindow: 500,
|
||||
ticksRate: 2,
|
||||
samplesCount: 15
|
||||
}, null, (prop, source) => {
|
||||
return !utils.isUndefined(source[prop]);
|
||||
});
|
||||
options = utils.toFlatObject(
|
||||
options,
|
||||
{
|
||||
maxRate: 0,
|
||||
chunkSize: 64 * 1024,
|
||||
minChunkSize: 100,
|
||||
timeWindow: 500,
|
||||
ticksRate: 2,
|
||||
samplesCount: 15,
|
||||
},
|
||||
null,
|
||||
(prop, source) => {
|
||||
return !utils.isUndefined(source[prop]);
|
||||
}
|
||||
);
|
||||
|
||||
super({
|
||||
readableHighWaterMark: options.chunkSize
|
||||
readableHighWaterMark: options.chunkSize,
|
||||
});
|
||||
|
||||
const internals = this[kInternals] = {
|
||||
const internals = (this[kInternals] = {
|
||||
timeWindow: options.timeWindow,
|
||||
chunkSize: options.chunkSize,
|
||||
maxRate: options.maxRate,
|
||||
@@ -32,10 +37,10 @@ class AxiosTransformStream extends stream.Transform{
|
||||
notifiedBytesLoaded: 0,
|
||||
ts: Date.now(),
|
||||
bytes: 0,
|
||||
onReadCallback: null
|
||||
};
|
||||
onReadCallback: null,
|
||||
});
|
||||
|
||||
this.on('newListener', event => {
|
||||
this.on('newListener', (event) => {
|
||||
if (event === 'progress') {
|
||||
if (!internals.isCaptured) {
|
||||
internals.isCaptured = true;
|
||||
@@ -63,8 +68,11 @@ class AxiosTransformStream extends stream.Transform{
|
||||
const timeWindow = internals.timeWindow;
|
||||
|
||||
const divider = 1000 / timeWindow;
|
||||
const bytesThreshold = (maxRate / divider);
|
||||
const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
|
||||
const bytesThreshold = maxRate / divider;
|
||||
const minChunkSize =
|
||||
internals.minChunkSize !== false
|
||||
? Math.max(internals.minChunkSize, bytesThreshold * 0.01)
|
||||
: 0;
|
||||
|
||||
const pushChunk = (_chunk, _callback) => {
|
||||
const bytes = Buffer.byteLength(_chunk);
|
||||
@@ -81,7 +89,7 @@ class AxiosTransformStream extends stream.Transform{
|
||||
process.nextTick(_callback);
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const transformChunk = (_chunk, _callback) => {
|
||||
const chunkSize = Buffer.byteLength(_chunk);
|
||||
@@ -93,7 +101,7 @@ class AxiosTransformStream extends stream.Transform{
|
||||
if (maxRate) {
|
||||
const now = Date.now();
|
||||
|
||||
if (!internals.ts || (passed = (now - internals.ts)) >= timeWindow) {
|
||||
if (!internals.ts || (passed = now - internals.ts) >= timeWindow) {
|
||||
internals.ts = now;
|
||||
bytesLeft = bytesThreshold - internals.bytes;
|
||||
internals.bytes = bytesLeft < 0 ? -bytesLeft : 0;
|
||||
@@ -116,14 +124,19 @@ class AxiosTransformStream extends stream.Transform{
|
||||
}
|
||||
}
|
||||
|
||||
if (maxChunkSize && chunkSize > maxChunkSize && (chunkSize - maxChunkSize) > minChunkSize) {
|
||||
if (maxChunkSize && chunkSize > maxChunkSize && chunkSize - maxChunkSize > minChunkSize) {
|
||||
chunkRemainder = _chunk.subarray(maxChunkSize);
|
||||
_chunk = _chunk.subarray(0, maxChunkSize);
|
||||
}
|
||||
|
||||
pushChunk(_chunk, chunkRemainder ? () => {
|
||||
process.nextTick(_callback, null, chunkRemainder);
|
||||
} : _callback);
|
||||
pushChunk(
|
||||
_chunk,
|
||||
chunkRemainder
|
||||
? () => {
|
||||
process.nextTick(_callback, null, chunkRemainder);
|
||||
}
|
||||
: _callback
|
||||
);
|
||||
};
|
||||
|
||||
transformChunk(chunk, function transformNextChunk(err, _chunk) {
|
||||
|
||||
Reference in New Issue
Block a user