@ziplayer/plugin 0.2.1-dev-2 → 0.2.1-dev-3
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-converter.d.ts","sourceRoot":"","sources":["../../src/utils/stream-converter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,cAAc,EAAE,aAAa,GAAE,MAAkB,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"stream-converter.d.ts","sourceRoot":"","sources":["../../src/utils/stream-converter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,cAAc,EAAE,aAAa,GAAE,MAAkB,GAAG,QAAQ,CAwI5G"}
|
|
@@ -55,69 +55,75 @@ function webStreamToNodeStream(webStream, highWaterMark = 64 * 1024) {
|
|
|
55
55
|
callback(error);
|
|
56
56
|
},
|
|
57
57
|
});
|
|
58
|
-
//
|
|
59
|
-
abortController = new AbortController();
|
|
60
|
-
// Create a reader from the Web Stream
|
|
61
|
-
reader = webStream.getReader();
|
|
62
|
-
// Read chunks with backpressure support
|
|
58
|
+
// Define pump function with backpressure handling
|
|
63
59
|
const pump = async () => {
|
|
60
|
+
let cleanup = false;
|
|
64
61
|
try {
|
|
65
62
|
while (pumpActive && reader) {
|
|
66
63
|
const { done, value } = await reader.read();
|
|
67
64
|
// Check if pump was stopped during read
|
|
68
65
|
if (!pumpActive || !reader) {
|
|
66
|
+
cleanup = true;
|
|
69
67
|
break;
|
|
70
68
|
}
|
|
71
69
|
if (done) {
|
|
72
70
|
nodeStream.push(null); // End the stream
|
|
71
|
+
cleanup = true;
|
|
73
72
|
break;
|
|
74
73
|
}
|
|
75
74
|
if (value && pumpActive) {
|
|
76
75
|
// Convert to Buffer and push
|
|
77
76
|
const buffer = Buffer.from(value);
|
|
78
77
|
// Check backpressure: push() returns false if internal buffer is full
|
|
79
|
-
// This means we should pause and let the consumer catch up
|
|
80
78
|
const shouldContinue = nodeStream.push(buffer);
|
|
81
79
|
if (!shouldContinue) {
|
|
82
80
|
// Internal buffer is full, pause reading
|
|
83
81
|
isReading = false;
|
|
84
|
-
|
|
82
|
+
return; // exit pump early; resume on drain or read
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
catch (error) {
|
|
90
|
-
|
|
88
|
+
cleanup = true;
|
|
91
89
|
if (pumpActive) {
|
|
92
90
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
93
|
-
// Ignore "Controller is already closed" and stream cancelled errors
|
|
94
91
|
if (errorMsg.includes("Controller is already closed") ||
|
|
95
92
|
errorMsg.includes("already been cancelled") ||
|
|
96
93
|
errorMsg.includes("stream closed") ||
|
|
97
94
|
errorMsg.includes("aborted")) {
|
|
98
|
-
// Stream was destroyed externally, just end cleanly
|
|
99
95
|
nodeStream.push(null);
|
|
100
96
|
}
|
|
101
97
|
else {
|
|
102
|
-
// Real error, report it
|
|
103
98
|
nodeStream.destroy(error);
|
|
104
99
|
}
|
|
105
100
|
}
|
|
106
101
|
}
|
|
107
102
|
finally {
|
|
108
|
-
// Mark as not reading
|
|
109
103
|
isReading = false;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
if (cleanup) {
|
|
105
|
+
try {
|
|
106
|
+
if (reader) {
|
|
107
|
+
await reader.cancel();
|
|
108
|
+
reader = null;
|
|
109
|
+
}
|
|
115
110
|
}
|
|
111
|
+
catch { }
|
|
112
|
+
pumpActive = false;
|
|
116
113
|
}
|
|
117
|
-
catch { }
|
|
118
|
-
pumpActive = false;
|
|
119
114
|
}
|
|
120
115
|
};
|
|
116
|
+
// Restart pump when backpressure is relieved
|
|
117
|
+
nodeStream.on("drain", () => {
|
|
118
|
+
if (!isReading && pumpActive && reader) {
|
|
119
|
+
isReading = true;
|
|
120
|
+
pump().catch((error) => {
|
|
121
|
+
if (pumpActive) {
|
|
122
|
+
console.error("[stream-converter] Pump error on drain:", error);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
121
127
|
// Start initial pump when stream is requested
|
|
122
128
|
// Note: pump will be called by read() callback for backpressure compliance
|
|
123
129
|
setImmediate(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-converter.js","sourceRoot":"","sources":["../../src/utils/stream-converter.ts"],"names":[],"mappings":";;AAYA,
|
|
1
|
+
{"version":3,"file":"stream-converter.js","sourceRoot":"","sources":["../../src/utils/stream-converter.ts"],"names":[],"mappings":";;AAYA,sDAwIC;AApJD,mCAAkC;AAElC;;;;;;;;;GASG;AACH,SAAgB,qBAAqB,CAAC,SAAyB,EAAE,gBAAwB,EAAE,GAAG,IAAI;IACjG,IAAI,MAAM,GAAuC,IAAI,CAAC;IACtD,IAAI,UAAU,GAAG,IAAI,CAAC;IACtB,IAAI,eAAe,GAA2B,IAAI,CAAC;IACnD,IAAI,SAAS,GAAG,KAAK,CAAC,CAAC,2BAA2B;IAElD,MAAM,UAAU,GAAG,IAAI,iBAAQ,CAAC;QAC/B,kEAAkE;QAClE,aAAa,EAAE,aAAa;QAE5B,IAAI,CAAC,IAAa;YACjB,oDAAoD;YACpD,IAAI,CAAC,SAAS,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;gBACxC,SAAS,GAAG,IAAI,CAAC;gBACjB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;oBACtB,IAAI,UAAU,EAAE,CAAC;wBAChB,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;oBACxD,CAAC;gBACF,CAAC,CAAC,C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AAG,EAAE;QAC3B,IAAI,CAAC,SAAS,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;YACxC,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACtB,IAAI,UAAU,EAAE,CAAC;oBAChB,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;gBACjE,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,8CAA8C;IAC9C,2EAA2E;IAC3E,YAAY,CAAC,GAAG,EAAE;QACjB,IAAI,UAAU,IAAI,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;YACxC,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACtB,IAAI,UAAU,EAAE,CAAC;oBAChB,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;gBAChE,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -58,25 +58,22 @@ export function webStreamToNodeStream(webStream: ReadableStream, highWaterMark:
|
|
|
58
58
|
},
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
//
|
|
62
|
-
abortController = new AbortController();
|
|
63
|
-
|
|
64
|
-
// Create a reader from the Web Stream
|
|
65
|
-
reader = webStream.getReader();
|
|
66
|
-
|
|
67
|
-
// Read chunks with backpressure support
|
|
61
|
+
// Define pump function with backpressure handling
|
|
68
62
|
const pump = async () => {
|
|
63
|
+
let cleanup = false;
|
|
69
64
|
try {
|
|
70
65
|
while (pumpActive && reader) {
|
|
71
66
|
const { done, value } = await reader.read();
|
|
72
67
|
|
|
73
68
|
// Check if pump was stopped during read
|
|
74
69
|
if (!pumpActive || !reader) {
|
|
70
|
+
cleanup = true;
|
|
75
71
|
break;
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
if (done) {
|
|
79
75
|
nodeStream.push(null); // End the stream
|
|
76
|
+
cleanup = true;
|
|
80
77
|
break;
|
|
81
78
|
}
|
|
82
79
|
|
|
@@ -85,50 +82,55 @@ export function webStreamToNodeStream(webStream: ReadableStream, highWaterMark:
|
|
|
85
82
|
const buffer = Buffer.from(value);
|
|
86
83
|
|
|
87
84
|
// Check backpressure: push() returns false if internal buffer is full
|
|
88
|
-
// This means we should pause and let the consumer catch up
|
|
89
85
|
const shouldContinue = nodeStream.push(buffer);
|
|
90
86
|
|
|
91
87
|
if (!shouldContinue) {
|
|
92
88
|
// Internal buffer is full, pause reading
|
|
93
89
|
isReading = false;
|
|
94
|
-
|
|
90
|
+
return; // exit pump early; resume on drain or read
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
94
|
} catch (error) {
|
|
99
|
-
|
|
95
|
+
cleanup = true;
|
|
100
96
|
if (pumpActive) {
|
|
101
97
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
102
|
-
|
|
103
|
-
// Ignore "Controller is already closed" and stream cancelled errors
|
|
104
98
|
if (
|
|
105
99
|
errorMsg.includes("Controller is already closed") ||
|
|
106
100
|
errorMsg.includes("already been cancelled") ||
|
|
107
101
|
errorMsg.includes("stream closed") ||
|
|
108
102
|
errorMsg.includes("aborted")
|
|
109
103
|
) {
|
|
110
|
-
// Stream was destroyed externally, just end cleanly
|
|
111
104
|
nodeStream.push(null);
|
|
112
105
|
} else {
|
|
113
|
-
// Real error, report it
|
|
114
106
|
nodeStream.destroy(error as Error);
|
|
115
107
|
}
|
|
116
108
|
}
|
|
117
109
|
} finally {
|
|
118
|
-
// Mark as not reading
|
|
119
110
|
isReading = false;
|
|
111
|
+
if (cleanup) {
|
|
112
|
+
try {
|
|
113
|
+
if (reader) {
|
|
114
|
+
await reader.cancel();
|
|
115
|
+
reader = null;
|
|
116
|
+
}
|
|
117
|
+
} catch {}
|
|
118
|
+
pumpActive = false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
120
122
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
// Restart pump when backpressure is relieved
|
|
124
|
+
nodeStream.on("drain", () => {
|
|
125
|
+
if (!isReading && pumpActive && reader) {
|
|
126
|
+
isReading = true;
|
|
127
|
+
pump().catch((error) => {
|
|
128
|
+
if (pumpActive) {
|
|
129
|
+
console.error("[stream-converter] Pump error on drain:", error);
|
|
126
130
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
pumpActive = false;
|
|
131
|
+
});
|
|
130
132
|
}
|
|
131
|
-
};
|
|
133
|
+
});
|
|
132
134
|
|
|
133
135
|
// Start initial pump when stream is requested
|
|
134
136
|
// Note: pump will be called by read() callback for backpressure compliance
|