@yume-chan/stream-extra 0.0.17 → 0.0.19

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.
Files changed (104) hide show
  1. package/CHANGELOG.json +33 -9
  2. package/CHANGELOG.md +15 -2
  3. package/LICENSE +1 -1
  4. package/README.md +35 -3
  5. package/esm/buffered-transform.d.ts +11 -10
  6. package/esm/buffered-transform.d.ts.map +1 -1
  7. package/esm/buffered-transform.js +55 -49
  8. package/esm/buffered-transform.js.map +1 -1
  9. package/esm/buffered.d.ts +29 -27
  10. package/esm/buffered.d.ts.map +1 -1
  11. package/esm/buffered.js +128 -130
  12. package/esm/buffered.js.map +1 -1
  13. package/esm/chunk.d.ts +7 -4
  14. package/esm/chunk.d.ts.map +1 -1
  15. package/esm/chunk.js +48 -7
  16. package/esm/chunk.js.map +1 -1
  17. package/esm/consumable.d.ts +53 -0
  18. package/esm/consumable.d.ts.map +1 -0
  19. package/esm/consumable.js +178 -0
  20. package/esm/consumable.js.map +1 -0
  21. package/esm/decode-utf8.d.ts +4 -4
  22. package/esm/decode-utf8.d.ts.map +1 -1
  23. package/esm/decode-utf8.js +11 -11
  24. package/esm/decode-utf8.js.map +1 -1
  25. package/esm/distribution.d.ts +24 -0
  26. package/esm/distribution.d.ts.map +1 -0
  27. package/esm/distribution.js +99 -0
  28. package/esm/distribution.js.map +1 -0
  29. package/esm/duplex.d.ts +48 -47
  30. package/esm/duplex.d.ts.map +1 -1
  31. package/esm/duplex.js +90 -88
  32. package/esm/duplex.js.map +1 -1
  33. package/esm/gather-string.d.ts +6 -6
  34. package/esm/gather-string.d.ts.map +1 -1
  35. package/esm/gather-string.js +15 -13
  36. package/esm/gather-string.js.map +1 -1
  37. package/esm/index.d.ts +16 -15
  38. package/esm/index.d.ts.map +1 -1
  39. package/esm/index.js +16 -15
  40. package/esm/index.js.map +1 -1
  41. package/esm/inspect.d.ts +4 -4
  42. package/esm/inspect.js +11 -11
  43. package/esm/pipe-from.d.ts +12 -12
  44. package/esm/pipe-from.d.ts.map +1 -1
  45. package/esm/pipe-from.js +23 -26
  46. package/esm/pipe-from.js.map +1 -1
  47. package/esm/push-readable.d.ts +19 -11
  48. package/esm/push-readable.d.ts.map +1 -1
  49. package/esm/push-readable.js +61 -46
  50. package/esm/push-readable.js.map +1 -1
  51. package/esm/split-string.d.ts +4 -4
  52. package/esm/split-string.d.ts.map +1 -1
  53. package/esm/split-string.js +24 -24
  54. package/esm/split-string.js.map +1 -1
  55. package/esm/stream.d.ts +25 -17
  56. package/esm/stream.d.ts.map +1 -1
  57. package/esm/stream.js +26 -3
  58. package/esm/stream.js.map +1 -1
  59. package/esm/struct-deserialize.d.ts +6 -6
  60. package/esm/struct-deserialize.d.ts.map +1 -1
  61. package/esm/struct-deserialize.js +8 -8
  62. package/esm/struct-deserialize.js.map +1 -1
  63. package/esm/struct-serialize.d.ts +5 -5
  64. package/esm/struct-serialize.d.ts.map +1 -1
  65. package/esm/struct-serialize.js +10 -10
  66. package/esm/struct-serialize.js.map +1 -1
  67. package/esm/trace.d.ts +16 -0
  68. package/esm/trace.d.ts.map +1 -0
  69. package/esm/trace.js +131 -0
  70. package/esm/trace.js.map +1 -0
  71. package/esm/wrap-readable.d.ts +21 -20
  72. package/esm/wrap-readable.d.ts.map +1 -1
  73. package/esm/wrap-readable.js +56 -56
  74. package/esm/wrap-readable.js.map +1 -1
  75. package/esm/wrap-writable.d.ts +14 -12
  76. package/esm/wrap-writable.d.ts.map +1 -1
  77. package/esm/wrap-writable.js +62 -52
  78. package/esm/wrap-writable.js.map +1 -1
  79. package/package.json +13 -9
  80. package/src/buffered-transform.ts +32 -17
  81. package/src/buffered.ts +14 -15
  82. package/src/consumable.ts +281 -0
  83. package/src/decode-utf8.ts +3 -2
  84. package/src/distribution.ts +113 -0
  85. package/src/duplex.ts +27 -10
  86. package/src/gather-string.ts +5 -3
  87. package/src/index.ts +16 -15
  88. package/src/inspect.ts +1 -1
  89. package/src/pipe-from.ts +11 -10
  90. package/src/push-readable.ts +77 -46
  91. package/src/split-string.ts +5 -2
  92. package/src/stream.ts +48 -6
  93. package/src/struct-deserialize.ts +6 -4
  94. package/src/struct-serialize.ts +4 -2
  95. package/src/wrap-readable.ts +30 -12
  96. package/src/wrap-writable.ts +34 -11
  97. package/tsconfig.build.json +1 -1
  98. package/tsconfig.build.tsbuildinfo +1 -1
  99. package/esm/native.d.ts +0 -240
  100. package/esm/native.d.ts.map +0 -1
  101. package/esm/native.js +0 -60
  102. package/esm/native.js.map +0 -1
  103. package/src/chunk.ts +0 -15
  104. package/src/native.ts +0 -362
package/CHANGELOG.json CHANGED
@@ -1,11 +1,35 @@
1
1
  {
2
- "name": "@yume-chan/stream-extra",
3
- "entries": [
4
- {
5
- "version": "0.0.17",
6
- "tag": "@yume-chan/stream-extra_v0.0.17",
7
- "date": "Tue, 18 Oct 2022 09:32:30 GMT",
8
- "comments": {}
9
- }
10
- ]
2
+ "name": "@yume-chan/stream-extra",
3
+ "entries": [
4
+ {
5
+ "version": "0.0.19",
6
+ "tag": "@yume-chan/stream-extra_v0.0.19",
7
+ "date": "Sun, 09 Apr 2023 05:55:33 GMT",
8
+ "comments": {
9
+ "none": [
10
+ {
11
+ "comment": "Add an option to combine small chunks into target size in `ChunkStream`, and rename it to `DistributionStream`"
12
+ }
13
+ ]
14
+ }
15
+ },
16
+ {
17
+ "version": "0.0.18",
18
+ "tag": "@yume-chan/stream-extra_v0.0.18",
19
+ "date": "Wed, 25 Jan 2023 21:33:49 GMT",
20
+ "comments": {
21
+ "none": [
22
+ {
23
+ "comment": "Change to load native Web Streams API implementation from `globalThis` if available"
24
+ }
25
+ ]
26
+ }
27
+ },
28
+ {
29
+ "version": "0.0.17",
30
+ "tag": "@yume-chan/stream-extra_v0.0.17",
31
+ "date": "Tue, 18 Oct 2022 09:32:30 GMT",
32
+ "comments": {}
33
+ }
34
+ ]
11
35
  }
package/CHANGELOG.md CHANGED
@@ -1,9 +1,22 @@
1
1
  # Change Log - @yume-chan/stream-extra
2
2
 
3
- This log was last generated on Tue, 18 Oct 2022 09:32:30 GMT and should not be manually modified.
3
+ This log was last generated on Sun, 09 Apr 2023 05:55:33 GMT and should not be manually modified.
4
+
5
+ ## 0.0.19
6
+ Sun, 09 Apr 2023 05:55:33 GMT
7
+
8
+ ### Updates
9
+
10
+ - Add an option to combine small chunks into target size in `ChunkStream`, and rename it to `DistributionStream`
11
+
12
+ ## 0.0.18
13
+ Wed, 25 Jan 2023 21:33:49 GMT
14
+
15
+ ### Updates
16
+
17
+ - Change to load native Web Streams API implementation from `globalThis` if available
4
18
 
5
19
  ## 0.0.17
6
20
  Tue, 18 Oct 2022 09:32:30 GMT
7
21
 
8
22
  _Initial release_
9
-
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-2022 Simon Chan
3
+ Copyright (c) 2020-2023 Simon Chan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,11 +1,43 @@
1
1
  # @yume-chan/stream-extra
2
2
 
3
- Some useful extensions for Web Streams API.
3
+ Some useful extensions for working with binary streams. Conforms to the [Web Streams API](https://streams.spec.whatwg.org/).
4
4
 
5
- Currently it's using [web-streams-polyfill](https://github.com/MattiasBuelens/web-streams-polyfill) because it's hard to load native implementations from both browsers and Node.js. (An experimental implementation using Top Level Await is available in `native.ts`, but not exported).
5
+ ## Find an implementation
6
+
7
+ If all of `ReadableStream`, `WritableStream` and `TransformStream` fields are available on `globalThis`, they will be used. Otherwise, the [web-streams-polyfill](https://github.com/MattiasBuelens/web-streams-polyfill) package will be used.
8
+
9
+ Google Chrome 89 and Mozilla Firefox 102 provide full support for Web Streams API natively.
10
+
11
+ In Node.js, it's not possible to load the `stream/web` module while keeping the compatibility with both Web and bundlers:
12
+
13
+ - Webpack has poor support with Top Level Await, for example, Hot Module Replacement doesn't work when any module is using TLA.
14
+ - Web doesn't have the `module` module, thus requires a shim in import map.
15
+
16
+ Assigning `ReadableStream`, `WritableStream` and `TransformStream` from `stream/web` module to `globalThis`, before loading this library, will still work. Other custom polyfill can also be loaded this way.
17
+
18
+ ## Compatibility issue with `ReadableStream#pipeTo` and `ReadableStream#pipeThrough`
19
+
20
+ The [Web Streams API spec](https://streams.spec.whatwg.org/#readable-stream-pipe-to) specifies that `ReadableStream#pipeTo` must check the argument to be an instance of `WritableStream`, so it can optimize the performance by calling internal methods directly.
21
+
22
+ Native implementations will perform this check, so `new globalThis.ReadableStream().pipeTo(new Polyfill.WritableStream())` will throw an error.
23
+
24
+ The `WrapReadableStream` class can be used to bypass this check:
25
+
26
+ ```ts
27
+ import { WrapReadableStream } from "@yume-chan/stream-extra";
28
+ import { WritableStream as PolyfillWritableStream } from "web-streams-polyfill";
29
+
30
+ const nativeReadable = new globalThis.ReadableStream();
31
+ const wrappedReadable = new WrapReadableStream(new globalThis.ReadableStream());
32
+
33
+ nativeReadable.pipeTo(new PolyfillWritableStream()); // Error
34
+ wrappedReadable.pipeTo(new PolyfillWritableStream()); // OK
35
+ ```
36
+
37
+ web-streams-polyfill package's `ReadableStream#pipeTo` only uses public methods, so it can be used with any `WritableStream` implementation.
6
38
 
7
39
  ## `BufferedReadableStream`
8
40
 
9
41
  Allowing reading specified amount of data by buffering incoming data.
10
42
 
11
- It's not a Web Stream API `ReadableStream`, because `ReadableStream` doesn't allow hinting the desired read size (except using BYOB readable, but causes extra allocations for small reads).
43
+ It's not a Web Streams API `ReadableStream`, because `ReadableStream` doesn't allow hinting the desired read size (except using BYOB readable, but causes extra allocations for small reads).
@@ -1,11 +1,12 @@
1
- import type { ValueOrPromise } from '@yume-chan/struct';
2
- import { BufferedReadableStream } from './buffered.js';
3
- import { ReadableStream, ReadableWritablePair, WritableStream } from './stream.js';
4
- export declare class BufferedTransformStream<T> implements ReadableWritablePair<T, Uint8Array> {
5
- private _readable;
6
- get readable(): ReadableStream<T>;
7
- private _writable;
8
- get writable(): WritableStream<Uint8Array>;
9
- constructor(transform: (stream: BufferedReadableStream) => ValueOrPromise<T>);
10
- }
1
+ import type { ValueOrPromise } from "@yume-chan/struct";
2
+ import { BufferedReadableStream } from "./buffered.js";
3
+ import type { ReadableWritablePair } from "./stream.js";
4
+ import { ReadableStream, WritableStream } from "./stream.js";
5
+ export declare class BufferedTransformStream<T> implements ReadableWritablePair<T, Uint8Array> {
6
+ private _readable;
7
+ get readable(): ReadableStream<T>;
8
+ private _writable;
9
+ get writable(): WritableStream<Uint8Array>;
10
+ constructor(transform: (stream: BufferedReadableStream) => ValueOrPromise<T>);
11
+ }
11
12
  //# sourceMappingURL=buffered-transform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buffered-transform.d.ts","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAoC,MAAM,eAAe,CAAC;AAEzF,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGnF,qBAAa,uBAAuB,CAAC,CAAC,CAAE,YAAW,oBAAoB,CAAC,CAAC,EAAE,UAAU,CAAC;IAClF,OAAO,CAAC,SAAS,CAAoB;IACrC,IAAW,QAAQ,sBAA6B;IAEhD,OAAO,CAAC,SAAS,CAA6B;IAC9C,IAAW,QAAQ,+BAA6B;gBAEpC,SAAS,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,cAAc,CAAC,CAAC,CAAC;CA4C/E"}
1
+ {"version":3,"file":"buffered-transform.d.ts","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EACH,sBAAsB,EAEzB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7D,qBAAa,uBAAuB,CAAC,CAAC,CAClC,YAAW,oBAAoB,CAAC,CAAC,EAAE,UAAU,CAAC;IAE9C,OAAO,CAAC,SAAS,CAAoB;IACrC,IAAW,QAAQ,sBAElB;IAED,OAAO,CAAC,SAAS,CAA6B;IAC9C,IAAW,QAAQ,+BAElB;gBAGG,SAAS,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,cAAc,CAAC,CAAC,CAAC;CA8CvE"}
@@ -1,50 +1,56 @@
1
- import { BufferedReadableStream, BufferedReadableStreamEndedError } from './buffered.js';
2
- import { PushReadableStream } from './push-readable.js';
3
- import { ReadableStream, WritableStream } from './stream.js';
4
- // TODO: BufferedTransformStream: find better implementation
5
- export class BufferedTransformStream {
6
- _readable;
7
- get readable() { return this._readable; }
8
- _writable;
9
- get writable() { return this._writable; }
10
- constructor(transform) {
11
- // Convert incoming chunks to a `BufferedReadableStream`
12
- let sourceStreamController;
13
- const buffered = new BufferedReadableStream(new PushReadableStream(controller => sourceStreamController = controller));
14
- this._readable = new ReadableStream({
15
- async pull(controller) {
16
- try {
17
- const value = await transform(buffered);
18
- controller.enqueue(value);
19
- }
20
- catch (e) {
21
- // TODO: BufferedTransformStream: The semantic of stream ending is not clear
22
- // If the `transform` started but did not finish, it should really be an error?
23
- // But we can't detect that, unless there is a `peek` method on buffered stream.
24
- if (e instanceof BufferedReadableStreamEndedError) {
25
- controller.close();
26
- return;
27
- }
28
- throw e;
29
- }
30
- },
31
- cancel: (reason) => {
32
- // Propagate cancel to the source stream
33
- // So future writes will be rejected
34
- buffered.cancel(reason);
35
- }
36
- });
37
- this._writable = new WritableStream({
38
- async write(chunk) {
39
- await sourceStreamController.enqueue(chunk);
40
- },
41
- abort() {
42
- sourceStreamController.close();
43
- },
44
- close() {
45
- sourceStreamController.close();
46
- },
47
- });
48
- }
49
- }
1
+ import { BufferedReadableStream, BufferedReadableStreamEndedError, } from "./buffered.js";
2
+ import { PushReadableStream } from "./push-readable.js";
3
+ import { ReadableStream, WritableStream } from "./stream.js";
4
+ // TODO: BufferedTransformStream: find better implementation
5
+ export class BufferedTransformStream {
6
+ _readable;
7
+ get readable() {
8
+ return this._readable;
9
+ }
10
+ _writable;
11
+ get writable() {
12
+ return this._writable;
13
+ }
14
+ constructor(transform) {
15
+ // Convert incoming chunks to a `BufferedReadableStream`
16
+ let sourceStreamController;
17
+ const buffered = new BufferedReadableStream(new PushReadableStream((controller) => {
18
+ sourceStreamController = controller;
19
+ }));
20
+ this._readable = new ReadableStream({
21
+ async pull(controller) {
22
+ try {
23
+ const value = await transform(buffered);
24
+ controller.enqueue(value);
25
+ }
26
+ catch (e) {
27
+ // Treat `BufferedReadableStreamEndedError` as a normal end.
28
+ // If the `transform` method doesn't have enough data to return a value,
29
+ // it should throw another error to indicate that.
30
+ if (e instanceof BufferedReadableStreamEndedError) {
31
+ controller.close();
32
+ return;
33
+ }
34
+ throw e;
35
+ }
36
+ },
37
+ cancel: (reason) => {
38
+ // Propagate cancel to the source stream
39
+ // So future writes will be rejected
40
+ return buffered.cancel(reason);
41
+ },
42
+ });
43
+ this._writable = new WritableStream({
44
+ async write(chunk) {
45
+ await sourceStreamController.enqueue(chunk);
46
+ },
47
+ abort() {
48
+ sourceStreamController.close();
49
+ },
50
+ close() {
51
+ sourceStreamController.close();
52
+ },
53
+ });
54
+ }
55
+ }
50
56
  //# sourceMappingURL=buffered-transform.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"buffered-transform.js","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAgC,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,cAAc,EAAwB,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnF,4DAA4D;AAC5D,MAAM,OAAO,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QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACnC,CAAC;SACJ,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,IAAI,cAAc,CAAC;YAChC,KAAK,CAAC,KAAK,CAAC,KAAK;gBACb,MAAM,sBAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;YACD,KAAK;gBACD,sBAAsB,CAAC,KAAK,EAAE,CAAC;YACnC,CAAC;YACD,KAAK;gBACD,sBAAsB,CAAC,KAAK,EAAE,CAAC;YACnC,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
package/esm/buffered.d.ts CHANGED
@@ -1,28 +1,30 @@
1
- import type { ReadableStream, ReadableStreamDefaultReader } from "./stream.js";
2
- export declare class BufferedReadableStreamEndedError extends Error {
3
- constructor();
4
- }
5
- export declare class BufferedReadableStream {
6
- private buffered;
7
- private bufferedOffset;
8
- private bufferedLength;
9
- protected readonly stream: ReadableStream<Uint8Array>;
10
- protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
11
- constructor(stream: ReadableStream<Uint8Array>);
12
- private readSource;
13
- private readAsync;
14
- /**
15
- *
16
- * @param length
17
- * @returns
18
- */
19
- read(length: number): Uint8Array | Promise<Uint8Array>;
20
- /**
21
- * Return a readable stream with unconsumed data (if any) and
22
- * all data from the wrapped stream.
23
- * @returns A `ReadableStream`
24
- */
25
- release(): ReadableStream<Uint8Array>;
26
- cancel(reason?: any): Promise<void>;
27
- }
1
+ import type { ReadableStream, ReadableStreamDefaultReader } from "./stream.js";
2
+ export declare class BufferedReadableStreamEndedError extends Error {
3
+ constructor();
4
+ }
5
+ export declare class BufferedReadableStream {
6
+ private buffered;
7
+ private bufferedOffset;
8
+ private bufferedLength;
9
+ private _position;
10
+ get position(): number;
11
+ protected readonly stream: ReadableStream<Uint8Array>;
12
+ protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
13
+ constructor(stream: ReadableStream<Uint8Array>);
14
+ private readSource;
15
+ private readAsync;
16
+ /**
17
+ *
18
+ * @param length
19
+ * @returns
20
+ */
21
+ read(length: number): Uint8Array | Promise<Uint8Array>;
22
+ /**
23
+ * Return a readable stream with unconsumed data (if any) and
24
+ * all data from the wrapped stream.
25
+ * @returns A `ReadableStream`
26
+ */
27
+ release(): ReadableStream<Uint8Array>;
28
+ cancel(reason?: unknown): Promise<void>;
29
+ }
28
30
  //# sourceMappingURL=buffered.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buffered.d.ts","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/E,qBAAa,gCAAiC,SAAQ,KAAK;;CAO1D;AAED,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,cAAc,CAAK;IAE3B,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAEtD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAC;gBAEhD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC;YAKvC,UAAU;YAQV,SAAS;IAmDvB;;;;OAIG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAoB7D;;;;OAIG;IACI,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC;IA6BrC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG;CAG7B"}
1
+ {"version":3,"file":"buffered.d.ts","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/E,qBAAa,gCAAiC,SAAQ,KAAK;;CAO1D;AAED,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,cAAc,CAAK;IAE3B,OAAO,CAAC,SAAS,CAAK;IACtB,IAAW,QAAQ,WAElB;IAED,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACtD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAC;gBAEhD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC;YAKvC,UAAU;YASV,SAAS;IAmDvB;;;;OAIG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAoB7D;;;;OAIG;IACI,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC;IAuBrC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO;CAGjC"}
package/esm/buffered.js CHANGED
@@ -1,131 +1,129 @@
1
- import { PushReadableStream } from "./push-readable.js";
2
- export class BufferedReadableStreamEndedError extends Error {
3
- constructor() {
4
- super('Stream ended');
5
- // Fix Error's prototype chain when compiling to ES5
6
- Object.setPrototypeOf(this, new.target.prototype);
7
- }
8
- }
9
- export class BufferedReadableStream {
10
- buffered;
11
- bufferedOffset = 0;
12
- bufferedLength = 0;
13
- stream;
14
- reader;
15
- constructor(stream) {
16
- this.stream = stream;
17
- this.reader = stream.getReader();
18
- }
19
- async readSource() {
20
- const { done, value } = await this.reader.read();
21
- if (done) {
22
- throw new BufferedReadableStreamEndedError();
23
- }
24
- return value;
25
- }
26
- async readAsync(length, initial) {
27
- let result;
28
- let index;
29
- if (initial) {
30
- result = new Uint8Array(length);
31
- result.set(initial);
32
- index = initial.byteLength;
33
- length -= initial.byteLength;
34
- }
35
- else {
36
- const array = await this.readSource();
37
- if (array.byteLength === length) {
38
- return array;
39
- }
40
- if (array.byteLength > length) {
41
- this.buffered = array;
42
- this.bufferedOffset = length;
43
- this.bufferedLength = array.byteLength - length;
44
- return array.subarray(0, length);
45
- }
46
- result = new Uint8Array(length);
47
- result.set(array);
48
- index = array.byteLength;
49
- length -= array.byteLength;
50
- }
51
- while (length > 0) {
52
- const array = await this.readSource();
53
- if (array.byteLength === length) {
54
- result.set(array, index);
55
- return result;
56
- }
57
- if (array.byteLength > length) {
58
- this.buffered = array;
59
- this.bufferedOffset = length;
60
- this.bufferedLength = array.byteLength - length;
61
- result.set(array.subarray(0, length), index);
62
- return result;
63
- }
64
- result.set(array, index);
65
- index += array.byteLength;
66
- length -= array.byteLength;
67
- }
68
- return result;
69
- }
70
- /**
71
- *
72
- * @param length
73
- * @returns
74
- */
75
- read(length) {
76
- // PERF: Add a synchronous path for reading from internal buffer
77
- if (this.buffered) {
78
- const array = this.buffered;
79
- const offset = this.bufferedOffset;
80
- if (this.bufferedLength > length) {
81
- // PERF: `subarray` is slow
82
- // don't use it until absolutely necessary
83
- this.bufferedOffset += length;
84
- this.bufferedLength -= length;
85
- return array.subarray(offset, offset + length);
86
- }
87
- this.buffered = undefined;
88
- return this.readAsync(length, array.subarray(offset));
89
- }
90
- return this.readAsync(length);
91
- }
92
- /**
93
- * Return a readable stream with unconsumed data (if any) and
94
- * all data from the wrapped stream.
95
- * @returns A `ReadableStream`
96
- */
97
- release() {
98
- if (this.buffered) {
99
- return new PushReadableStream(async (controller) => {
100
- // Put the remaining data back to the stream
101
- await controller.enqueue(this.buffered);
102
- // Manually pipe the stream
103
- while (true) {
104
- try {
105
- const { done, value } = await this.reader.read();
106
- if (done) {
107
- controller.close();
108
- break;
109
- }
110
- else {
111
- await controller.enqueue(value);
112
- }
113
- }
114
- catch (e) {
115
- controller.error(e);
116
- break;
117
- }
118
- }
119
- });
120
- }
121
- else {
122
- // Simply release the reader and return the stream
123
- this.reader.releaseLock();
124
- return this.stream;
125
- }
126
- }
127
- cancel(reason) {
128
- return this.reader.cancel(reason);
129
- }
130
- }
1
+ import { PushReadableStream } from "./push-readable.js";
2
+ export class BufferedReadableStreamEndedError extends Error {
3
+ constructor() {
4
+ super("Stream ended");
5
+ // Fix Error's prototype chain when compiling to ES5
6
+ Object.setPrototypeOf(this, new.target.prototype);
7
+ }
8
+ }
9
+ export class BufferedReadableStream {
10
+ buffered;
11
+ bufferedOffset = 0;
12
+ bufferedLength = 0;
13
+ _position = 0;
14
+ get position() {
15
+ return this._position;
16
+ }
17
+ stream;
18
+ reader;
19
+ constructor(stream) {
20
+ this.stream = stream;
21
+ this.reader = stream.getReader();
22
+ }
23
+ async readSource() {
24
+ const { done, value } = await this.reader.read();
25
+ if (done) {
26
+ throw new BufferedReadableStreamEndedError();
27
+ }
28
+ this._position += value.byteLength;
29
+ return value;
30
+ }
31
+ async readAsync(length, initial) {
32
+ let result;
33
+ let index;
34
+ if (initial) {
35
+ result = new Uint8Array(length);
36
+ result.set(initial);
37
+ index = initial.byteLength;
38
+ length -= initial.byteLength;
39
+ }
40
+ else {
41
+ const array = await this.readSource();
42
+ if (array.byteLength === length) {
43
+ return array;
44
+ }
45
+ if (array.byteLength > length) {
46
+ this.buffered = array;
47
+ this.bufferedOffset = length;
48
+ this.bufferedLength = array.byteLength - length;
49
+ return array.subarray(0, length);
50
+ }
51
+ result = new Uint8Array(length);
52
+ result.set(array);
53
+ index = array.byteLength;
54
+ length -= array.byteLength;
55
+ }
56
+ while (length > 0) {
57
+ const array = await this.readSource();
58
+ if (array.byteLength === length) {
59
+ result.set(array, index);
60
+ return result;
61
+ }
62
+ if (array.byteLength > length) {
63
+ this.buffered = array;
64
+ this.bufferedOffset = length;
65
+ this.bufferedLength = array.byteLength - length;
66
+ result.set(array.subarray(0, length), index);
67
+ return result;
68
+ }
69
+ result.set(array, index);
70
+ index += array.byteLength;
71
+ length -= array.byteLength;
72
+ }
73
+ return result;
74
+ }
75
+ /**
76
+ *
77
+ * @param length
78
+ * @returns
79
+ */
80
+ read(length) {
81
+ // PERF: Add a synchronous path for reading from internal buffer
82
+ if (this.buffered) {
83
+ const array = this.buffered;
84
+ const offset = this.bufferedOffset;
85
+ if (this.bufferedLength > length) {
86
+ // PERF: `subarray` is slow
87
+ // don't use it until absolutely necessary
88
+ this.bufferedOffset += length;
89
+ this.bufferedLength -= length;
90
+ return array.subarray(offset, offset + length);
91
+ }
92
+ this.buffered = undefined;
93
+ return this.readAsync(length, array.subarray(offset));
94
+ }
95
+ return this.readAsync(length);
96
+ }
97
+ /**
98
+ * Return a readable stream with unconsumed data (if any) and
99
+ * all data from the wrapped stream.
100
+ * @returns A `ReadableStream`
101
+ */
102
+ release() {
103
+ if (this.buffered) {
104
+ return new PushReadableStream(async (controller) => {
105
+ // Put the remaining data back to the stream
106
+ await controller.enqueue(this.buffered);
107
+ // Manually pipe the stream
108
+ while (true) {
109
+ const { done, value } = await this.reader.read();
110
+ if (done) {
111
+ return;
112
+ }
113
+ else {
114
+ await controller.enqueue(value);
115
+ }
116
+ }
117
+ });
118
+ }
119
+ else {
120
+ // Simply release the reader and return the stream
121
+ this.reader.releaseLock();
122
+ return this.stream;
123
+ }
124
+ }
125
+ cancel(reason) {
126
+ return this.reader.cancel(reason);
127
+ }
128
+ }
131
129
  //# sourceMappingURL=buffered.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"buffered.js","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IACvD;QACI,KAAK,CAAC,cAAc,CAAC,CAAC;QAEtB,oDAAoD;QACpD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACJ;AAED,MAAM,OAAO,sBAAsB;IACvB,QAAQ,CAAyB;IACjC,cAAc,GAAG,CAAC,CAAC;IACnB,cAAc,GAAG,CAAC,CAAC;IAER,MAAM,CAA6B;IAEnC,MAAM,CAA0C;IAEnE,YAAmB,MAAkC;QACjD,IAAI,CAAC,MA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