@azure/storage-common 12.0.0-alpha.20250520.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/browser/BufferScheduler-browser.d.mts.map +1 -0
- package/dist/browser/BufferScheduler-browser.mjs.map +1 -0
- package/dist/browser/BufferScheduler.d.ts +3 -0
- package/dist/browser/BufferScheduler.js +8 -0
- package/dist/browser/BuffersStream.d.ts +41 -0
- package/dist/browser/BuffersStream.d.ts.map +1 -0
- package/dist/browser/BuffersStream.js +83 -0
- package/dist/browser/BuffersStream.js.map +1 -0
- package/dist/browser/PooledBuffer.d.ts +63 -0
- package/dist/browser/PooledBuffer.d.ts.map +1 -0
- package/dist/browser/PooledBuffer.js +87 -0
- package/dist/browser/PooledBuffer.js.map +1 -0
- package/dist/browser/cache.d.ts +3 -0
- package/dist/browser/cache.d.ts.map +1 -0
- package/dist/browser/cache.js +11 -0
- package/dist/browser/cache.js.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +5 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/commonjs/BufferScheduler.d.ts +157 -0
- package/dist/commonjs/BufferScheduler.d.ts.map +1 -0
- package/dist/commonjs/BufferScheduler.js +256 -0
- package/dist/commonjs/BufferScheduler.js.map +1 -0
- package/dist/commonjs/BuffersStream.d.ts +41 -0
- package/dist/commonjs/BuffersStream.d.ts.map +1 -0
- package/dist/commonjs/BuffersStream.js +87 -0
- package/dist/commonjs/BuffersStream.js.map +1 -0
- package/dist/commonjs/PooledBuffer.d.ts +63 -0
- package/dist/commonjs/PooledBuffer.d.ts.map +1 -0
- package/dist/commonjs/PooledBuffer.js +92 -0
- package/dist/commonjs/PooledBuffer.js.map +1 -0
- package/dist/commonjs/cache.d.ts +3 -0
- package/dist/commonjs/cache.d.ts.map +1 -0
- package/dist/commonjs/cache.js +14 -0
- package/dist/commonjs/cache.js.map +1 -0
- package/dist/commonjs/index.d.ts +3 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +10 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/esm/BufferScheduler.d.ts +157 -0
- package/dist/esm/BufferScheduler.d.ts.map +1 -0
- package/dist/esm/BufferScheduler.js +252 -0
- package/dist/esm/BufferScheduler.js.map +1 -0
- package/dist/esm/BuffersStream.d.ts +41 -0
- package/dist/esm/BuffersStream.d.ts.map +1 -0
- package/dist/esm/BuffersStream.js +83 -0
- package/dist/esm/BuffersStream.js.map +1 -0
- package/dist/esm/PooledBuffer.d.ts +63 -0
- package/dist/esm/PooledBuffer.d.ts.map +1 -0
- package/dist/esm/PooledBuffer.js +87 -0
- package/dist/esm/PooledBuffer.js.map +1 -0
- package/dist/esm/cache.d.ts +3 -0
- package/dist/esm/cache.d.ts.map +1 -0
- package/dist/esm/cache.js +11 -0
- package/dist/esm/cache.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/react-native/BufferScheduler.d.ts +157 -0
- package/dist/react-native/BufferScheduler.d.ts.map +1 -0
- package/dist/react-native/BufferScheduler.js +252 -0
- package/dist/react-native/BufferScheduler.js.map +1 -0
- package/dist/react-native/BuffersStream.d.ts +41 -0
- package/dist/react-native/BuffersStream.d.ts.map +1 -0
- package/dist/react-native/BuffersStream.js +83 -0
- package/dist/react-native/BuffersStream.js.map +1 -0
- package/dist/react-native/PooledBuffer.d.ts +63 -0
- package/dist/react-native/PooledBuffer.d.ts.map +1 -0
- package/dist/react-native/PooledBuffer.js +87 -0
- package/dist/react-native/PooledBuffer.js.map +1 -0
- package/dist/react-native/cache.d.ts +3 -0
- package/dist/react-native/cache.d.ts.map +1 -0
- package/dist/react-native/cache.js +11 -0
- package/dist/react-native/cache.js.map +1 -0
- package/dist/react-native/index.d.ts +3 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +5 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/package.json +104 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Azure Storage Common library for JavaScript
|
|
2
|
+
|
|
3
|
+
- For internal use only.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
- For internal use only.
|
|
8
|
+
|
|
9
|
+
## Key concepts
|
|
10
|
+
|
|
11
|
+
- For internal use only.
|
|
12
|
+
|
|
13
|
+
## Examples
|
|
14
|
+
|
|
15
|
+
- For internal use only.
|
|
16
|
+
|
|
17
|
+
## Troubleshooting
|
|
18
|
+
|
|
19
|
+
- For internal use only.
|
|
20
|
+
|
|
21
|
+
## Next steps
|
|
22
|
+
|
|
23
|
+
- For internal use only.
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
- For internal use only.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferScheduler-browser.d.mts","sourceRoot":"","sources":["../../src/BufferScheduler-browser.mts"],"names":[],"mappings":"AAMA,qBAAa,eAAe;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferScheduler-browser.mjs","sourceRoot":"","sources":["../../src/BufferScheduler-browser.mts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,6EAA6E;AAC7E,0CAA0C;AAC1C,+DAA+D;AAC/D,MAAM,OAAO,eAAe;CAAG","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file is used as a shim of \"BufferScheduler\" for some browser bundlers\n// when trying to bundle \"BufferScheduler\"\n// \"BufferScheduler\" class is only available in Node.js runtime\nexport class BufferScheduler {}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
// This file is used as a shim of "BufferScheduler" for some browser bundlers
|
|
4
|
+
// when trying to bundle "BufferScheduler"
|
|
5
|
+
// "BufferScheduler" class is only available in Node.js runtime
|
|
6
|
+
export class BufferScheduler {
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=BufferScheduler-browser.mjs.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReadableOptions } from "node:stream";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
/**
|
|
4
|
+
* Options to configure the BuffersStream.
|
|
5
|
+
*/
|
|
6
|
+
export interface BuffersStreamOptions extends ReadableOptions {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* This class generates a readable stream from the data in an array of buffers.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BuffersStream extends Readable {
|
|
12
|
+
private buffers;
|
|
13
|
+
private byteLength;
|
|
14
|
+
/**
|
|
15
|
+
* The offset of data to be read in the current buffer.
|
|
16
|
+
*/
|
|
17
|
+
private byteOffsetInCurrentBuffer;
|
|
18
|
+
/**
|
|
19
|
+
* The index of buffer to be read in the array of buffers.
|
|
20
|
+
*/
|
|
21
|
+
private bufferIndex;
|
|
22
|
+
/**
|
|
23
|
+
* The total length of data already read.
|
|
24
|
+
*/
|
|
25
|
+
private pushedBytesLength;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of BuffersStream that will emit the data
|
|
28
|
+
* contained in the array of buffers.
|
|
29
|
+
*
|
|
30
|
+
* @param buffers - Array of buffers containing the data
|
|
31
|
+
* @param byteLength - The total length of data contained in the buffers
|
|
32
|
+
*/
|
|
33
|
+
constructor(buffers: Buffer[], byteLength: number, options?: BuffersStreamOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Internal _read() that will be called when the stream wants to pull more data in.
|
|
36
|
+
*
|
|
37
|
+
* @param size - Optional. The size of data to be read
|
|
38
|
+
*/
|
|
39
|
+
_read(size?: number): void;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=BuffersStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuffersStream.d.ts","sourceRoot":"","sources":["../../src/BuffersStream.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,eAAe;CAAG;AAEhE;;GAEG;AACH,qBAAa,aAAc,SAAQ,QAAQ;IAwBvC,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;IAxBpB;;OAEG;IACH,OAAO,CAAC,yBAAyB,CAAS;IAE1C;;OAEG;IACH,OAAO,CAAC,WAAW,CAAS;IAE5B;;OAEG;IACH,OAAO,CAAC,iBAAiB,CAAS;IAElC;;;;;;OAMG;gBAEO,OAAO,EAAE,MAAM,EAAE,EACjB,UAAU,EAAE,MAAM,EAC1B,OAAO,CAAC,EAAE,oBAAoB;IAiBhC;;;;OAIG;IACI,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;CA+ClC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
/**
|
|
5
|
+
* This class generates a readable stream from the data in an array of buffers.
|
|
6
|
+
*/
|
|
7
|
+
export class BuffersStream extends Readable {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of BuffersStream that will emit the data
|
|
10
|
+
* contained in the array of buffers.
|
|
11
|
+
*
|
|
12
|
+
* @param buffers - Array of buffers containing the data
|
|
13
|
+
* @param byteLength - The total length of data contained in the buffers
|
|
14
|
+
*/
|
|
15
|
+
constructor(buffers, byteLength, options) {
|
|
16
|
+
super(options);
|
|
17
|
+
this.buffers = buffers;
|
|
18
|
+
this.byteLength = byteLength;
|
|
19
|
+
this.byteOffsetInCurrentBuffer = 0;
|
|
20
|
+
this.bufferIndex = 0;
|
|
21
|
+
this.pushedBytesLength = 0;
|
|
22
|
+
// check byteLength is no larger than buffers[] total length
|
|
23
|
+
let buffersLength = 0;
|
|
24
|
+
for (const buf of this.buffers) {
|
|
25
|
+
buffersLength += buf.byteLength;
|
|
26
|
+
}
|
|
27
|
+
if (buffersLength < this.byteLength) {
|
|
28
|
+
throw new Error("Data size shouldn't be larger than the total length of buffers.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Internal _read() that will be called when the stream wants to pull more data in.
|
|
33
|
+
*
|
|
34
|
+
* @param size - Optional. The size of data to be read
|
|
35
|
+
*/
|
|
36
|
+
_read(size) {
|
|
37
|
+
if (this.pushedBytesLength >= this.byteLength) {
|
|
38
|
+
this.push(null);
|
|
39
|
+
}
|
|
40
|
+
if (!size) {
|
|
41
|
+
size = this.readableHighWaterMark;
|
|
42
|
+
}
|
|
43
|
+
const outBuffers = [];
|
|
44
|
+
let i = 0;
|
|
45
|
+
while (i < size && this.pushedBytesLength < this.byteLength) {
|
|
46
|
+
// The last buffer may be longer than the data it contains.
|
|
47
|
+
const remainingDataInAllBuffers = this.byteLength - this.pushedBytesLength;
|
|
48
|
+
const remainingCapacityInThisBuffer = this.buffers[this.bufferIndex].byteLength - this.byteOffsetInCurrentBuffer;
|
|
49
|
+
const remaining = Math.min(remainingCapacityInThisBuffer, remainingDataInAllBuffers);
|
|
50
|
+
if (remaining > size - i) {
|
|
51
|
+
// chunkSize = size - i
|
|
52
|
+
const end = this.byteOffsetInCurrentBuffer + size - i;
|
|
53
|
+
outBuffers.push(this.buffers[this.bufferIndex].slice(this.byteOffsetInCurrentBuffer, end));
|
|
54
|
+
this.pushedBytesLength += size - i;
|
|
55
|
+
this.byteOffsetInCurrentBuffer = end;
|
|
56
|
+
i = size;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// chunkSize = remaining
|
|
61
|
+
const end = this.byteOffsetInCurrentBuffer + remaining;
|
|
62
|
+
outBuffers.push(this.buffers[this.bufferIndex].slice(this.byteOffsetInCurrentBuffer, end));
|
|
63
|
+
if (remaining === remainingCapacityInThisBuffer) {
|
|
64
|
+
// this.buffers[this.bufferIndex] used up, shift to next one
|
|
65
|
+
this.byteOffsetInCurrentBuffer = 0;
|
|
66
|
+
this.bufferIndex++;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.byteOffsetInCurrentBuffer = end;
|
|
70
|
+
}
|
|
71
|
+
this.pushedBytesLength += remaining;
|
|
72
|
+
i += remaining;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (outBuffers.length > 1) {
|
|
76
|
+
this.push(Buffer.concat(outBuffers));
|
|
77
|
+
}
|
|
78
|
+
else if (outBuffers.length === 1) {
|
|
79
|
+
this.push(outBuffers[0]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=BuffersStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuffersStream.js","sourceRoot":"","sources":["../../src/BuffersStream.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOvC;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAgBzC;;;;;;OAMG;IACH,YACU,OAAiB,EACjB,UAAkB,EAC1B,OAA8B;QAE9B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJP,YAAO,GAAP,OAAO,CAAU;QACjB,eAAU,GAAV,UAAU,CAAQ;QAI1B,IAAI,CAAC,yBAAyB,GAAG,CAAC,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;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C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC3F,IAAI,CAAC,iBAAiB,IAAI,IAAI,GAAG,CAAC,CAAC;gBACnC,IAAI,CAAC,yBAAyB,GAAG,GAAG,CAAC;gBACrC,CAAC,GAAG,IAAI,CAAC;gBACT,MAAM;YACR,CAAC;iBAAM,CAAC;gBACN,wBAAwB;gBACxB,MAAM,GAAG,GAAG,IAAI,CAAC,yBAAyB,GAAG,SAAS,CAAC;gBACvD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC3F,IAAI,SAAS,KAAK,6BAA6B,EAAE,CAAC;oBAChD,4DAA4D;oBAC5D,IAAI,CAAC,yBAAyB,GAAG,CAAC,CAAC;oBACnC,IAAI,CAAC,WAAW,EAAE,CAAC;gBACrB,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,yBAAyB,GAAG,GAAG,CAAC;gBACvC,CAAC;gBACD,IAAI,CAAC,iBAAiB,IAAI,SAAS,CAAC;gBACpC,CAAC,IAAI,SAAS,CAAC;YACjB,CAAC;QACH,CAAC;QAED,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;QACvC,CAAC;aAAM,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ReadableOptions } from \"node:stream\";\nimport { Readable } from \"node:stream\";\n\n/**\n * Options to configure the BuffersStream.\n */\nexport interface BuffersStreamOptions extends ReadableOptions {}\n\n/**\n * This class generates a readable stream from the data in an array of buffers.\n */\nexport class BuffersStream extends Readable {\n /**\n * The offset of data to be read in the current buffer.\n */\n private byteOffsetInCurrentBuffer: number;\n\n /**\n * The index of buffer to be read in the array of buffers.\n */\n private bufferIndex: number;\n\n /**\n * The total length of data already read.\n */\n private pushedBytesLength: number;\n\n /**\n * Creates an instance of BuffersStream that will emit the data\n * contained in the array of buffers.\n *\n * @param buffers - Array of buffers containing the data\n * @param byteLength - The total length of data contained in the buffers\n */\n constructor(\n private buffers: Buffer[],\n private byteLength: number,\n options?: BuffersStreamOptions,\n ) {\n super(options);\n this.byteOffsetInCurrentBuffer = 0;\n this.bufferIndex = 0;\n this.pushedBytesLength = 0;\n\n // check byteLength is no larger than buffers[] total length\n let buffersLength = 0;\n for (const buf of this.buffers) {\n buffersLength += buf.byteLength;\n }\n if (buffersLength < this.byteLength) {\n throw new Error(\"Data size shouldn't be larger than the total length of buffers.\");\n }\n }\n\n /**\n * Internal _read() that will be called when the stream wants to pull more data in.\n *\n * @param size - Optional. The size of data to be read\n */\n public _read(size?: number): void {\n if (this.pushedBytesLength >= this.byteLength) {\n this.push(null);\n }\n\n if (!size) {\n size = this.readableHighWaterMark;\n }\n\n const outBuffers: Buffer[] = [];\n let i = 0;\n while (i < size && this.pushedBytesLength < this.byteLength) {\n // The last buffer may be longer than the data it contains.\n const remainingDataInAllBuffers = this.byteLength - this.pushedBytesLength;\n const remainingCapacityInThisBuffer =\n this.buffers[this.bufferIndex].byteLength - this.byteOffsetInCurrentBuffer;\n const remaining = Math.min(remainingCapacityInThisBuffer, remainingDataInAllBuffers);\n if (remaining > size - i) {\n // chunkSize = size - i\n const end = this.byteOffsetInCurrentBuffer + size - i;\n outBuffers.push(this.buffers[this.bufferIndex].slice(this.byteOffsetInCurrentBuffer, end));\n this.pushedBytesLength += size - i;\n this.byteOffsetInCurrentBuffer = end;\n i = size;\n break;\n } else {\n // chunkSize = remaining\n const end = this.byteOffsetInCurrentBuffer + remaining;\n outBuffers.push(this.buffers[this.bufferIndex].slice(this.byteOffsetInCurrentBuffer, end));\n if (remaining === remainingCapacityInThisBuffer) {\n // this.buffers[this.bufferIndex] used up, shift to next one\n this.byteOffsetInCurrentBuffer = 0;\n this.bufferIndex++;\n } else {\n this.byteOffsetInCurrentBuffer = end;\n }\n this.pushedBytesLength += remaining;\n i += remaining;\n }\n }\n\n if (outBuffers.length > 1) {\n this.push(Buffer.concat(outBuffers));\n } else if (outBuffers.length === 1) {\n this.push(outBuffers[0]);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Readable } from "node:stream";
|
|
2
|
+
/**
|
|
3
|
+
* This class provides a buffer container which conceptually has no hard size limit.
|
|
4
|
+
* It accepts a capacity, an array of input buffers and the total length of input data.
|
|
5
|
+
* It will allocate an internal "buffer" of the capacity and fill the data in the input buffers
|
|
6
|
+
* into the internal "buffer" serially with respect to the total length.
|
|
7
|
+
* Then by calling PooledBuffer.getReadableStream(), you can get a readable stream
|
|
8
|
+
* assembled from all the data in the internal "buffer".
|
|
9
|
+
*/
|
|
10
|
+
export declare class PooledBuffer {
|
|
11
|
+
/**
|
|
12
|
+
* Internal buffers used to keep the data.
|
|
13
|
+
* Each buffer has a length of the maxBufferLength except last one.
|
|
14
|
+
*/
|
|
15
|
+
private buffers;
|
|
16
|
+
/**
|
|
17
|
+
* The total size of internal buffers.
|
|
18
|
+
*/
|
|
19
|
+
private readonly capacity;
|
|
20
|
+
/**
|
|
21
|
+
* The total size of data contained in internal buffers.
|
|
22
|
+
*/
|
|
23
|
+
private _size;
|
|
24
|
+
/**
|
|
25
|
+
* The size of the data contained in the pooled buffers.
|
|
26
|
+
*/
|
|
27
|
+
get size(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Creates an instance of PooledBuffer with given capacity.
|
|
30
|
+
* Internal buffers are allocated but contains no data.
|
|
31
|
+
* Users may call the {@link PooledBuffer.fill} method to fill this
|
|
32
|
+
* pooled buffer with data.
|
|
33
|
+
*
|
|
34
|
+
* @param capacity - Total capacity of the internal buffers
|
|
35
|
+
*/
|
|
36
|
+
constructor(capacity: number);
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of PooledBuffer with given capacity.
|
|
39
|
+
* Internal buffers are allocated and filled with data in the input buffers serially
|
|
40
|
+
* with respect to the total length.
|
|
41
|
+
*
|
|
42
|
+
* @param capacity - Total capacity of the internal buffers
|
|
43
|
+
* @param buffers - Input buffers containing the data to be filled in the pooled buffer
|
|
44
|
+
* @param totalLength - Total length of the data to be filled in.
|
|
45
|
+
*/
|
|
46
|
+
constructor(capacity: number, buffers: Buffer[], totalLength: number);
|
|
47
|
+
/**
|
|
48
|
+
* Fill the internal buffers with data in the input buffers serially
|
|
49
|
+
* with respect to the total length and the total capacity of the internal buffers.
|
|
50
|
+
* Data copied will be shift out of the input buffers.
|
|
51
|
+
*
|
|
52
|
+
* @param buffers - Input buffers containing the data to be filled in the pooled buffer
|
|
53
|
+
* @param totalLength - Total length of the data to be filled in.
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
fill(buffers: Buffer[], totalLength: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get the readable stream assembled from all the data in the internal buffers.
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
getReadableStream(): Readable;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=PooledBuffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PooledBuffer.d.ts","sourceRoot":"","sources":["../../src/PooledBuffer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAS5C;;;;;;;GAOG;AACH,qBAAa,YAAY;IACvB;;;OAGG;IACH,OAAO,CAAC,OAAO,CAAgB;IAE/B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC;;OAEG;IACH,OAAO,CAAC,KAAK,CAAS;IAEtB;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;;;;;;OAOG;gBACS,QAAQ,EAAE,MAAM;IAE5B;;;;;;;;OAQG;gBACS,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM;IAoBpE;;;;;;;;OAQG;IACI,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAiCzD;;;OAGG;IACI,iBAAiB,IAAI,QAAQ;CAGrC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { BuffersStream } from "./BuffersStream.js";
|
|
4
|
+
import buffer from "node:buffer";
|
|
5
|
+
/**
|
|
6
|
+
* maxBufferLength is max size of each buffer in the pooled buffers.
|
|
7
|
+
*/
|
|
8
|
+
const maxBufferLength = buffer.constants.MAX_LENGTH;
|
|
9
|
+
/**
|
|
10
|
+
* This class provides a buffer container which conceptually has no hard size limit.
|
|
11
|
+
* It accepts a capacity, an array of input buffers and the total length of input data.
|
|
12
|
+
* It will allocate an internal "buffer" of the capacity and fill the data in the input buffers
|
|
13
|
+
* into the internal "buffer" serially with respect to the total length.
|
|
14
|
+
* Then by calling PooledBuffer.getReadableStream(), you can get a readable stream
|
|
15
|
+
* assembled from all the data in the internal "buffer".
|
|
16
|
+
*/
|
|
17
|
+
export class PooledBuffer {
|
|
18
|
+
/**
|
|
19
|
+
* The size of the data contained in the pooled buffers.
|
|
20
|
+
*/
|
|
21
|
+
get size() {
|
|
22
|
+
return this._size;
|
|
23
|
+
}
|
|
24
|
+
constructor(capacity, buffers, totalLength) {
|
|
25
|
+
/**
|
|
26
|
+
* Internal buffers used to keep the data.
|
|
27
|
+
* Each buffer has a length of the maxBufferLength except last one.
|
|
28
|
+
*/
|
|
29
|
+
this.buffers = [];
|
|
30
|
+
this.capacity = capacity;
|
|
31
|
+
this._size = 0;
|
|
32
|
+
// allocate
|
|
33
|
+
const bufferNum = Math.ceil(capacity / maxBufferLength);
|
|
34
|
+
for (let i = 0; i < bufferNum; i++) {
|
|
35
|
+
let len = i === bufferNum - 1 ? capacity % maxBufferLength : maxBufferLength;
|
|
36
|
+
if (len === 0) {
|
|
37
|
+
len = maxBufferLength;
|
|
38
|
+
}
|
|
39
|
+
this.buffers.push(Buffer.allocUnsafe(len));
|
|
40
|
+
}
|
|
41
|
+
if (buffers) {
|
|
42
|
+
this.fill(buffers, totalLength);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Fill the internal buffers with data in the input buffers serially
|
|
47
|
+
* with respect to the total length and the total capacity of the internal buffers.
|
|
48
|
+
* Data copied will be shift out of the input buffers.
|
|
49
|
+
*
|
|
50
|
+
* @param buffers - Input buffers containing the data to be filled in the pooled buffer
|
|
51
|
+
* @param totalLength - Total length of the data to be filled in.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
fill(buffers, totalLength) {
|
|
55
|
+
this._size = Math.min(this.capacity, totalLength);
|
|
56
|
+
let i = 0, j = 0, targetOffset = 0, sourceOffset = 0, totalCopiedNum = 0;
|
|
57
|
+
while (totalCopiedNum < this._size) {
|
|
58
|
+
const source = buffers[i];
|
|
59
|
+
const target = this.buffers[j];
|
|
60
|
+
const copiedNum = source.copy(target, targetOffset, sourceOffset);
|
|
61
|
+
totalCopiedNum += copiedNum;
|
|
62
|
+
sourceOffset += copiedNum;
|
|
63
|
+
targetOffset += copiedNum;
|
|
64
|
+
if (sourceOffset === source.length) {
|
|
65
|
+
i++;
|
|
66
|
+
sourceOffset = 0;
|
|
67
|
+
}
|
|
68
|
+
if (targetOffset === target.length) {
|
|
69
|
+
j++;
|
|
70
|
+
targetOffset = 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// clear copied from source buffers
|
|
74
|
+
buffers.splice(0, i);
|
|
75
|
+
if (buffers.length > 0) {
|
|
76
|
+
buffers[0] = buffers[0].slice(sourceOffset);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the readable stream assembled from all the data in the internal buffers.
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
getReadableStream() {
|
|
84
|
+
return new BuffersStream(this.buffers, this.size);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=PooledBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PooledBuffer.js","sourceRoot":"","sources":["../../src/PooledBuffer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC;;GAEG;AAEH,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,OAAO,YAAY;IAiBvB;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAsBD,YAAY,QAAgB,EAAE,OAAkB,EAAE,WAAoB;QA3CtE;;;WAGG;QACK,YAAO,GAAa,EAAE,CAAC;QAwC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QAEf,WAAW;QACX,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC,CAAC;QACxD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,IAAI,GAAG,GAAG,CAAC,KAAK,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,eAAe,C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,mCAAmC;QACnC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACrB,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,iBAAiB;QACtB,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { BuffersStream } from \"./BuffersStream.js\";\nimport type { Readable } from \"node:stream\";\nimport buffer from \"node:buffer\";\n\n/**\n * maxBufferLength is max size of each buffer in the pooled buffers.\n */\n\nconst maxBufferLength = buffer.constants.MAX_LENGTH;\n\n/**\n * This class provides a buffer container which conceptually has no hard size limit.\n * It accepts a capacity, an array of input buffers and the total length of input data.\n * It will allocate an internal \"buffer\" of the capacity and fill the data in the input buffers\n * into the internal \"buffer\" serially with respect to the total length.\n * Then by calling PooledBuffer.getReadableStream(), you can get a readable stream\n * assembled from all the data in the internal \"buffer\".\n */\nexport class PooledBuffer {\n /**\n * Internal buffers used to keep the data.\n * Each buffer has a length of the maxBufferLength except last one.\n */\n private buffers: Buffer[] = [];\n\n /**\n * The total size of internal buffers.\n */\n private readonly capacity: number;\n\n /**\n * The total size of data contained in internal buffers.\n */\n private _size: number;\n\n /**\n * The size of the data contained in the pooled buffers.\n */\n public get size(): number {\n return this._size;\n }\n\n /**\n * Creates an instance of PooledBuffer with given capacity.\n * Internal buffers are allocated but contains no data.\n * Users may call the {@link PooledBuffer.fill} method to fill this\n * pooled buffer with data.\n *\n * @param capacity - Total capacity of the internal buffers\n */\n constructor(capacity: number);\n\n /**\n * Creates an instance of PooledBuffer with given capacity.\n * Internal buffers are allocated and filled with data in the input buffers serially\n * with respect to the total length.\n *\n * @param capacity - Total capacity of the internal buffers\n * @param buffers - Input buffers containing the data to be filled in the pooled buffer\n * @param totalLength - Total length of the data to be filled in.\n */\n constructor(capacity: number, buffers: Buffer[], totalLength: number);\n constructor(capacity: number, buffers?: Buffer[], totalLength?: number) {\n this.capacity = capacity;\n this._size = 0;\n\n // allocate\n const bufferNum = Math.ceil(capacity / maxBufferLength);\n for (let i = 0; i < bufferNum; i++) {\n let len = i === bufferNum - 1 ? capacity % maxBufferLength : maxBufferLength;\n if (len === 0) {\n len = maxBufferLength;\n }\n this.buffers.push(Buffer.allocUnsafe(len));\n }\n\n if (buffers) {\n this.fill(buffers, totalLength!);\n }\n }\n\n /**\n * Fill the internal buffers with data in the input buffers serially\n * with respect to the total length and the total capacity of the internal buffers.\n * Data copied will be shift out of the input buffers.\n *\n * @param buffers - Input buffers containing the data to be filled in the pooled buffer\n * @param totalLength - Total length of the data to be filled in.\n *\n */\n public fill(buffers: Buffer[], totalLength: number): void {\n this._size = Math.min(this.capacity, totalLength);\n\n let i = 0,\n j = 0,\n targetOffset = 0,\n sourceOffset = 0,\n totalCopiedNum = 0;\n while (totalCopiedNum < this._size) {\n const source = buffers[i];\n const target = this.buffers[j];\n const copiedNum = source.copy(target, targetOffset, sourceOffset);\n\n totalCopiedNum += copiedNum;\n sourceOffset += copiedNum;\n targetOffset += copiedNum;\n if (sourceOffset === source.length) {\n i++;\n sourceOffset = 0;\n }\n if (targetOffset === target.length) {\n j++;\n targetOffset = 0;\n }\n }\n\n // clear copied from source buffers\n buffers.splice(0, i);\n if (buffers.length > 0) {\n buffers[0] = buffers[0].slice(sourceOffset);\n }\n }\n\n /**\n * Get the readable stream assembled from all the data in the internal buffers.\n *\n */\n public getReadableStream(): Readable {\n return new BuffersStream(this.buffers, this.size);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAK5D,wBAAgB,0BAA0B,IAAI,UAAU,CAKvD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { createDefaultHttpClient } from "@azure/core-rest-pipeline";
|
|
4
|
+
let _defaultHttpClient;
|
|
5
|
+
export function getCachedDefaultHttpClient() {
|
|
6
|
+
if (!_defaultHttpClient) {
|
|
7
|
+
_defaultHttpClient = createDefaultHttpClient();
|
|
8
|
+
}
|
|
9
|
+
return _defaultHttpClient;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/cache.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,IAAI,kBAA8B,CAAC;AAEnC,MAAM,UAAU,0BAA0B;IACxC,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,kBAAkB,GAAG,uBAAuB,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient } from \"@azure/core-rest-pipeline\";\nimport { createDefaultHttpClient } from \"@azure/core-rest-pipeline\";\n\nlet _defaultHttpClient: HttpClient;\n\nexport function getCachedDefaultHttpClient(): HttpClient {\n if (!_defaultHttpClient) {\n _defaultHttpClient = createDefaultHttpClient();\n }\n return _defaultHttpClient;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport * from \"./BufferScheduler.js\";\nexport { getCachedDefaultHttpClient } from \"./cache.js\";\n"]}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OutgoingHandler is an async function triggered by BufferScheduler.
|
|
3
|
+
*/
|
|
4
|
+
export declare type OutgoingHandler = (body: () => NodeJS.ReadableStream, length: number, offset?: number) => Promise<any>;
|
|
5
|
+
/**
|
|
6
|
+
* This class accepts a Node.js Readable stream as input, and keeps reading data
|
|
7
|
+
* from the stream into the internal buffer structure, until it reaches maxBuffers.
|
|
8
|
+
* Every available buffer will try to trigger outgoingHandler.
|
|
9
|
+
*
|
|
10
|
+
* The internal buffer structure includes an incoming buffer array, and a outgoing
|
|
11
|
+
* buffer array. The incoming buffer array includes the "empty" buffers can be filled
|
|
12
|
+
* with new incoming data. The outgoing array includes the filled buffers to be
|
|
13
|
+
* handled by outgoingHandler. Every above buffer size is defined by parameter bufferSize.
|
|
14
|
+
*
|
|
15
|
+
* NUM_OF_ALL_BUFFERS = BUFFERS_IN_INCOMING + BUFFERS_IN_OUTGOING + BUFFERS_UNDER_HANDLING
|
|
16
|
+
*
|
|
17
|
+
* NUM_OF_ALL_BUFFERS lesser than or equal to maxBuffers
|
|
18
|
+
*
|
|
19
|
+
* PERFORMANCE IMPROVEMENT TIPS:
|
|
20
|
+
* 1. Input stream highWaterMark is better to set a same value with bufferSize
|
|
21
|
+
* parameter, which will avoid Buffer.concat() operations.
|
|
22
|
+
* 2. concurrency should set a smaller value than maxBuffers, which is helpful to
|
|
23
|
+
* reduce the possibility when a outgoing handler waits for the stream data.
|
|
24
|
+
* in this situation, outgoing handlers are blocked.
|
|
25
|
+
* Outgoing queue shouldn't be empty.
|
|
26
|
+
*/
|
|
27
|
+
export declare class BufferScheduler {
|
|
28
|
+
/**
|
|
29
|
+
* Size of buffers in incoming and outgoing queues. This class will try to align
|
|
30
|
+
* data read from Readable stream into buffer chunks with bufferSize defined.
|
|
31
|
+
*/
|
|
32
|
+
private readonly bufferSize;
|
|
33
|
+
/**
|
|
34
|
+
* How many buffers can be created or maintained.
|
|
35
|
+
*/
|
|
36
|
+
private readonly maxBuffers;
|
|
37
|
+
/**
|
|
38
|
+
* A Node.js Readable stream.
|
|
39
|
+
*/
|
|
40
|
+
private readonly readable;
|
|
41
|
+
/**
|
|
42
|
+
* OutgoingHandler is an async function triggered by BufferScheduler when there
|
|
43
|
+
* are available buffers in outgoing array.
|
|
44
|
+
*/
|
|
45
|
+
private readonly outgoingHandler;
|
|
46
|
+
/**
|
|
47
|
+
* An internal event emitter.
|
|
48
|
+
*/
|
|
49
|
+
private readonly emitter;
|
|
50
|
+
/**
|
|
51
|
+
* Concurrency of executing outgoingHandlers. (0 lesser than concurrency lesser than or equal to maxBuffers)
|
|
52
|
+
*/
|
|
53
|
+
private readonly concurrency;
|
|
54
|
+
/**
|
|
55
|
+
* An internal offset marker to track data offset in bytes of next outgoingHandler.
|
|
56
|
+
*/
|
|
57
|
+
private offset;
|
|
58
|
+
/**
|
|
59
|
+
* An internal marker to track whether stream is end.
|
|
60
|
+
*/
|
|
61
|
+
private isStreamEnd;
|
|
62
|
+
/**
|
|
63
|
+
* An internal marker to track whether stream or outgoingHandler returns error.
|
|
64
|
+
*/
|
|
65
|
+
private isError;
|
|
66
|
+
/**
|
|
67
|
+
* How many handlers are executing.
|
|
68
|
+
*/
|
|
69
|
+
private executingOutgoingHandlers;
|
|
70
|
+
/**
|
|
71
|
+
* Encoding of the input Readable stream which has string data type instead of Buffer.
|
|
72
|
+
*/
|
|
73
|
+
private encoding?;
|
|
74
|
+
/**
|
|
75
|
+
* How many buffers have been allocated.
|
|
76
|
+
*/
|
|
77
|
+
private numBuffers;
|
|
78
|
+
/**
|
|
79
|
+
* Because this class doesn't know how much data every time stream pops, which
|
|
80
|
+
* is defined by highWaterMarker of the stream. So BufferScheduler will cache
|
|
81
|
+
* data received from the stream, when data in unresolvedDataArray exceeds the
|
|
82
|
+
* blockSize defined, it will try to concat a blockSize of buffer, fill into available
|
|
83
|
+
* buffers from incoming and push to outgoing array.
|
|
84
|
+
*/
|
|
85
|
+
private unresolvedDataArray;
|
|
86
|
+
/**
|
|
87
|
+
* How much data consisted in unresolvedDataArray.
|
|
88
|
+
*/
|
|
89
|
+
private unresolvedLength;
|
|
90
|
+
/**
|
|
91
|
+
* The array includes all the available buffers can be used to fill data from stream.
|
|
92
|
+
*/
|
|
93
|
+
private incoming;
|
|
94
|
+
/**
|
|
95
|
+
* The array (queue) includes all the buffers filled from stream data.
|
|
96
|
+
*/
|
|
97
|
+
private outgoing;
|
|
98
|
+
/**
|
|
99
|
+
* Creates an instance of BufferScheduler.
|
|
100
|
+
*
|
|
101
|
+
* @param readable - A Node.js Readable stream
|
|
102
|
+
* @param bufferSize - Buffer size of every maintained buffer
|
|
103
|
+
* @param maxBuffers - How many buffers can be allocated
|
|
104
|
+
* @param outgoingHandler - An async function scheduled to be
|
|
105
|
+
* triggered when a buffer fully filled
|
|
106
|
+
* with stream data
|
|
107
|
+
* @param concurrency - Concurrency of executing outgoingHandlers (>0)
|
|
108
|
+
* @param encoding - [Optional] Encoding of Readable stream when it's a string stream
|
|
109
|
+
*/
|
|
110
|
+
constructor(readable: NodeJS.ReadableStream, bufferSize: number, maxBuffers: number, outgoingHandler: OutgoingHandler, concurrency: number, encoding?: BufferEncoding);
|
|
111
|
+
/**
|
|
112
|
+
* Start the scheduler, will return error when stream of any of the outgoingHandlers
|
|
113
|
+
* returns error.
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
do(): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Insert a new data into unresolved array.
|
|
119
|
+
*
|
|
120
|
+
* @param data -
|
|
121
|
+
*/
|
|
122
|
+
private appendUnresolvedData;
|
|
123
|
+
/**
|
|
124
|
+
* Try to shift a buffer with size in blockSize. The buffer returned may be less
|
|
125
|
+
* than blockSize when data in unresolvedDataArray is less than bufferSize.
|
|
126
|
+
*
|
|
127
|
+
*/
|
|
128
|
+
private shiftBufferFromUnresolvedDataArray;
|
|
129
|
+
/**
|
|
130
|
+
* Resolve data in unresolvedDataArray. For every buffer with size in blockSize
|
|
131
|
+
* shifted, it will try to get (or allocate a buffer) from incoming, and fill it,
|
|
132
|
+
* then push it into outgoing to be handled by outgoing handler.
|
|
133
|
+
*
|
|
134
|
+
* Return false when available buffers in incoming are not enough, else true.
|
|
135
|
+
*
|
|
136
|
+
* @returns Return false when buffers in incoming are not enough, else true.
|
|
137
|
+
*/
|
|
138
|
+
private resolveData;
|
|
139
|
+
/**
|
|
140
|
+
* Try to trigger a outgoing handler for every buffer in outgoing. Stop when
|
|
141
|
+
* concurrency reaches.
|
|
142
|
+
*/
|
|
143
|
+
private triggerOutgoingHandlers;
|
|
144
|
+
/**
|
|
145
|
+
* Trigger a outgoing handler for a buffer shifted from outgoing.
|
|
146
|
+
*
|
|
147
|
+
* @param buffer -
|
|
148
|
+
*/
|
|
149
|
+
private triggerOutgoingHandler;
|
|
150
|
+
/**
|
|
151
|
+
* Return buffer used by outgoing handler into incoming.
|
|
152
|
+
*
|
|
153
|
+
* @param buffer -
|
|
154
|
+
*/
|
|
155
|
+
private reuseBuffer;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=BufferScheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferScheduler.d.ts","sourceRoot":"","sources":["../../src/BufferScheduler.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,CAAC,OAAO,MAAM,eAAe,GAAG,CACpC,IA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