@ziplayer/plugin 0.1.41 → 0.1.51

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.
@@ -1,79 +1,79 @@
1
- import { Readable } from "stream";
2
-
3
- /**
4
- * Converts a Web ReadableStream to a Node.js Readable stream
5
- */
6
- export function webStreamToNodeStream(webStream: ReadableStream): Readable {
7
- const nodeStream = new Readable({
8
- read() {
9
- // This will be handled by the Web Stream reader
10
- },
11
- });
12
-
13
- // Create a reader from the Web Stream
14
- const reader = webStream.getReader();
15
-
16
- // Read chunks and push to Node.js stream
17
- const pump = async () => {
18
- try {
19
- while (true) {
20
- const { done, value } = await reader.read();
21
- if (done) {
22
- nodeStream.push(null); // End the stream
23
- break;
24
- }
25
- nodeStream.push(Buffer.from(value));
26
- }
27
- } catch (error) {
28
- nodeStream.destroy(error as Error);
29
- }
30
- };
31
-
32
- // Start pumping data
33
- pump();
34
-
35
- return nodeStream;
36
- }
37
-
38
- /**
39
- * Converts a Web ReadableStream to a Node.js Readable stream with progress tracking
40
- */
41
- export function webStreamToNodeStreamWithProgress(
42
- webStream: ReadableStream,
43
- progressCallback?: (bytesRead: number) => void,
44
- ): Readable {
45
- const nodeStream = new Readable({
46
- read() {
47
- // This will be handled by the Web Stream reader
48
- },
49
- });
50
-
51
- let bytesRead = 0;
52
- const reader = webStream.getReader();
53
-
54
- const pump = async () => {
55
- try {
56
- while (true) {
57
- const { done, value } = await reader.read();
58
- if (done) {
59
- nodeStream.push(null); // End the stream
60
- break;
61
- }
62
-
63
- const buffer = Buffer.from(value);
64
- nodeStream.push(buffer);
65
-
66
- bytesRead += buffer.length;
67
- if (progressCallback) {
68
- progressCallback(bytesRead);
69
- }
70
- }
71
- } catch (error) {
72
- nodeStream.destroy(error as Error);
73
- }
74
- };
75
-
76
- pump();
77
-
78
- return nodeStream;
79
- }
1
+ import { Readable } from "stream";
2
+
3
+ /**
4
+ * Converts a Web ReadableStream to a Node.js Readable stream
5
+ */
6
+ export function webStreamToNodeStream(webStream: ReadableStream): Readable {
7
+ const nodeStream = new Readable({
8
+ read() {
9
+ // This will be handled by the Web Stream reader
10
+ },
11
+ });
12
+
13
+ // Create a reader from the Web Stream
14
+ const reader = webStream.getReader();
15
+
16
+ // Read chunks and push to Node.js stream
17
+ const pump = async () => {
18
+ try {
19
+ while (true) {
20
+ const { done, value } = await reader.read();
21
+ if (done) {
22
+ nodeStream.push(null); // End the stream
23
+ break;
24
+ }
25
+ nodeStream.push(Buffer.from(value));
26
+ }
27
+ } catch (error) {
28
+ nodeStream.destroy(error as Error);
29
+ }
30
+ };
31
+
32
+ // Start pumping data
33
+ pump();
34
+
35
+ return nodeStream;
36
+ }
37
+
38
+ /**
39
+ * Converts a Web ReadableStream to a Node.js Readable stream with progress tracking
40
+ */
41
+ export function webStreamToNodeStreamWithProgress(
42
+ webStream: ReadableStream,
43
+ progressCallback?: (bytesRead: number) => void,
44
+ ): Readable {
45
+ const nodeStream = new Readable({
46
+ read() {
47
+ // This will be handled by the Web Stream reader
48
+ },
49
+ });
50
+
51
+ let bytesRead = 0;
52
+ const reader = webStream.getReader();
53
+
54
+ const pump = async () => {
55
+ try {
56
+ while (true) {
57
+ const { done, value } = await reader.read();
58
+ if (done) {
59
+ nodeStream.push(null); // End the stream
60
+ break;
61
+ }
62
+
63
+ const buffer = Buffer.from(value);
64
+ nodeStream.push(buffer);
65
+
66
+ bytesRead += buffer.length;
67
+ if (progressCallback) {
68
+ progressCallback(bytesRead);
69
+ }
70
+ }
71
+ } catch (error) {
72
+ nodeStream.destroy(error as Error);
73
+ }
74
+ };
75
+
76
+ pump();
77
+
78
+ return nodeStream;
79
+ }