@editframe/cli 0.16.8-beta.0 ā 0.17.6-beta.0
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/dist/VERSION.d.ts +1 -1
- package/dist/VERSION.js +2 -4
- package/dist/commands/auth.js +16 -25
- package/dist/commands/check.js +81 -108
- package/dist/commands/mux.d.ts +1 -0
- package/dist/commands/preview.js +4 -1
- package/dist/commands/process-file.js +18 -34
- package/dist/commands/process.js +28 -31
- package/dist/commands/render.js +117 -157
- package/dist/commands/sync.js +3 -5
- package/dist/commands/webhook.js +48 -52
- package/dist/index.js +3 -7
- package/dist/operations/processRenderInfo.js +25 -31
- package/dist/operations/syncAssetsDirectory/SubAssetSync.js +11 -18
- package/dist/operations/syncAssetsDirectory/SyncCaption.js +46 -73
- package/dist/operations/syncAssetsDirectory/SyncFragmentIndex.js +53 -83
- package/dist/operations/syncAssetsDirectory/SyncImage.js +72 -99
- package/dist/operations/syncAssetsDirectory/SyncStatus.js +30 -37
- package/dist/operations/syncAssetsDirectory/SyncTrack.js +107 -143
- package/dist/operations/syncAssetsDirectory/doAssetSync.js +42 -46
- package/dist/operations/syncAssetsDirectory.js +55 -78
- package/dist/utils/createReadableStreamFromReadable.js +61 -78
- package/dist/utils/index.js +10 -16
- package/dist/utils/launchBrowserAndWaitForSDK.js +31 -43
- package/dist/utils/startDevServer.d.ts +1 -1
- package/dist/utils/startPreviewServer.d.ts +1 -1
- package/dist/utils/startPreviewServer.js +28 -34
- package/dist/utils/validateVideoResolution.js +19 -23
- package/dist/utils/withSpinner.js +10 -12
- package/package.json +8 -8
- package/src/commands/check.ts +2 -2
- package/src/commands/mux.ts +10 -0
- package/src/utils/createReadableStreamFromReadable.ts +3 -7
- package/src/utils/startDevServer.ts +5 -5
- package/src/utils/startPreviewServer.ts +1 -1
- package/test-fixtures/network.ts +38 -9
|
@@ -1,146 +1,110 @@
|
|
|
1
|
-
import { createReadStream } from "node:fs";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import { join, dirname, basename } from "node:path";
|
|
4
|
-
import { lookupISOBMFFFileByMd5, createISOBMFFFile, createISOBMFFTrack, uploadISOBMFFTrack } from "@editframe/api";
|
|
5
|
-
import { Probe } from "@editframe/assets";
|
|
6
|
-
import { createReadableStreamFromReadable } from "../../utils/createReadableStreamFromReadable.js";
|
|
7
1
|
import { getClient } from "../../utils/index.js";
|
|
2
|
+
import { createReadableStreamFromReadable } from "../../utils/createReadableStreamFromReadable.js";
|
|
8
3
|
import { SyncStatus } from "./SyncStatus.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Number(this.trackId),
|
|
115
|
-
createReadableStreamFromReadable(createReadStream(this.path)),
|
|
116
|
-
this.created?.byte_size
|
|
117
|
-
).whenUploaded();
|
|
118
|
-
}
|
|
119
|
-
async markSynced() {
|
|
120
|
-
if (!this.created) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
"Track not created. Should have been prevented by .isComplete()"
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
const byteSize = await this.byteSize();
|
|
126
|
-
await Promise.all([
|
|
127
|
-
this.syncStatus.markSynced({
|
|
128
|
-
version: "1",
|
|
129
|
-
complete: true,
|
|
130
|
-
id: `${this.created.file_id}:${this.created.track_id}`,
|
|
131
|
-
md5: this.md5,
|
|
132
|
-
byte_size: byteSize
|
|
133
|
-
}),
|
|
134
|
-
this.fileSyncStatus.markSynced({
|
|
135
|
-
version: "1",
|
|
136
|
-
complete: true,
|
|
137
|
-
id: this.created.file_id,
|
|
138
|
-
md5: this.md5,
|
|
139
|
-
byte_size: byteSize
|
|
140
|
-
})
|
|
141
|
-
]);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
export {
|
|
145
|
-
SyncTrack
|
|
4
|
+
import { createISOBMFFFile, createISOBMFFTrack, lookupISOBMFFFileByMd5, uploadISOBMFFTrack } from "@editframe/api";
|
|
5
|
+
import { basename, dirname, join } from "node:path";
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import { createReadStream } from "node:fs";
|
|
8
|
+
import { Probe } from "@editframe/assets";
|
|
9
|
+
var SyncTrack = class {
|
|
10
|
+
constructor(path$1, md5) {
|
|
11
|
+
this.path = path$1;
|
|
12
|
+
this.md5 = md5;
|
|
13
|
+
this.icon = "š¼";
|
|
14
|
+
this.label = "track";
|
|
15
|
+
this.syncStatus = new SyncStatus(this.path);
|
|
16
|
+
this.fileSyncStatus = new SyncStatus(join(dirname(this.path), "isobmff"));
|
|
17
|
+
this.created = null;
|
|
18
|
+
this._isoFile = null;
|
|
19
|
+
this._probeResult = null;
|
|
20
|
+
}
|
|
21
|
+
get isoFile() {
|
|
22
|
+
if (this._isoFile) return this._isoFile;
|
|
23
|
+
throw new Error("ISOBMFF file not found. Call prepare() first.");
|
|
24
|
+
}
|
|
25
|
+
async byteSize() {
|
|
26
|
+
return (await fs.stat(this.path)).size;
|
|
27
|
+
}
|
|
28
|
+
get probeResult() {
|
|
29
|
+
if (this._probeResult) return this._probeResult;
|
|
30
|
+
throw new Error("Probe result not found. Call prepare() first.");
|
|
31
|
+
}
|
|
32
|
+
get track() {
|
|
33
|
+
const [track] = this.probeResult.streams;
|
|
34
|
+
if (track) return track;
|
|
35
|
+
throw new Error(`No track found in track: ${this.path}`);
|
|
36
|
+
}
|
|
37
|
+
async prepare() {
|
|
38
|
+
const maybeIsoFile = await lookupISOBMFFFileByMd5(getClient(), this.md5);
|
|
39
|
+
if (maybeIsoFile) this._isoFile = maybeIsoFile;
|
|
40
|
+
else this._isoFile = await createISOBMFFFile(getClient(), {
|
|
41
|
+
md5: this.md5,
|
|
42
|
+
filename: basename(this.path).replace(/\.track-[\d]+.mp4$/, "")
|
|
43
|
+
});
|
|
44
|
+
this._probeResult = await Probe.probePath(this.path);
|
|
45
|
+
}
|
|
46
|
+
get trackId() {
|
|
47
|
+
const trackId = this.path.match(/track-([\d]+).mp4/)?.[1];
|
|
48
|
+
if (!trackId) throw new Error(`No track ID found for track: ${this.path}`);
|
|
49
|
+
return trackId;
|
|
50
|
+
}
|
|
51
|
+
get trackDuration() {
|
|
52
|
+
const track = this.track;
|
|
53
|
+
if (!track.duration) throw new Error(`No duration found in track: ${this.path}`);
|
|
54
|
+
if (typeof track.duration === "string") return Number.parseFloat(track.duration);
|
|
55
|
+
return track.duration;
|
|
56
|
+
}
|
|
57
|
+
async validate() {
|
|
58
|
+
this.trackId;
|
|
59
|
+
this.isoFile;
|
|
60
|
+
this.trackDuration;
|
|
61
|
+
}
|
|
62
|
+
async create() {
|
|
63
|
+
const track = this.track;
|
|
64
|
+
const isoFile = this.isoFile;
|
|
65
|
+
if (track.codec_type === "data") throw new Error(`Unsupported codec type: ${track.codec_type}`);
|
|
66
|
+
const createPayload = track.codec_type === "audio" ? {
|
|
67
|
+
type: track.codec_type,
|
|
68
|
+
file_id: isoFile.id,
|
|
69
|
+
track_id: Number(this.trackId),
|
|
70
|
+
probe_info: track,
|
|
71
|
+
duration_ms: Math.round(this.trackDuration * 1e3),
|
|
72
|
+
codec_name: track.codec_name,
|
|
73
|
+
byte_size: await this.byteSize()
|
|
74
|
+
} : {
|
|
75
|
+
type: track.codec_type,
|
|
76
|
+
file_id: isoFile.id,
|
|
77
|
+
track_id: Number(this.trackId),
|
|
78
|
+
probe_info: track,
|
|
79
|
+
duration_ms: Math.round(this.trackDuration * 1e3),
|
|
80
|
+
codec_name: track.codec_name,
|
|
81
|
+
byte_size: await this.byteSize()
|
|
82
|
+
};
|
|
83
|
+
this.created = await createISOBMFFTrack(getClient(), createPayload);
|
|
84
|
+
}
|
|
85
|
+
isComplete() {
|
|
86
|
+
return !!this.created?.complete;
|
|
87
|
+
}
|
|
88
|
+
async upload() {
|
|
89
|
+
if (!this.created) throw new Error("Track not created. Should have been prevented by .isComplete()");
|
|
90
|
+
await uploadISOBMFFTrack(getClient(), this.isoFile.id, Number(this.trackId), createReadableStreamFromReadable(createReadStream(this.path)), this.created?.byte_size).whenUploaded();
|
|
91
|
+
}
|
|
92
|
+
async markSynced() {
|
|
93
|
+
if (!this.created) throw new Error("Track not created. Should have been prevented by .isComplete()");
|
|
94
|
+
const byteSize = await this.byteSize();
|
|
95
|
+
await Promise.all([this.syncStatus.markSynced({
|
|
96
|
+
version: "1",
|
|
97
|
+
complete: true,
|
|
98
|
+
id: `${this.created.file_id}:${this.created.track_id}`,
|
|
99
|
+
md5: this.md5,
|
|
100
|
+
byte_size: byteSize
|
|
101
|
+
}), this.fileSyncStatus.markSynced({
|
|
102
|
+
version: "1",
|
|
103
|
+
complete: true,
|
|
104
|
+
id: this.created.file_id,
|
|
105
|
+
md5: this.md5,
|
|
106
|
+
byte_size: byteSize
|
|
107
|
+
})]);
|
|
108
|
+
}
|
|
146
109
|
};
|
|
110
|
+
export { SyncTrack };
|
|
@@ -1,48 +1,44 @@
|
|
|
1
1
|
const doAssetSync = async function* (assetSync) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
return;
|
|
45
|
-
};
|
|
46
|
-
export {
|
|
47
|
-
doAssetSync
|
|
2
|
+
if (await assetSync.syncStatus.isSynced()) {
|
|
3
|
+
yield {
|
|
4
|
+
status: "info",
|
|
5
|
+
message: `Sub-asset has already been synced: ${assetSync.path}`
|
|
6
|
+
};
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
await assetSync.prepare();
|
|
11
|
+
await assetSync.validate();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
14
|
+
throw new Error(`Error validating ${assetSync.label}: ${message}`);
|
|
15
|
+
}
|
|
16
|
+
yield {
|
|
17
|
+
status: "info",
|
|
18
|
+
message: `${assetSync.icon} Syncing ${assetSync.label}: ${assetSync.path}`
|
|
19
|
+
};
|
|
20
|
+
try {
|
|
21
|
+
await assetSync.create();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
24
|
+
throw new Error(`Error creating ${assetSync.label}: ${message}`);
|
|
25
|
+
}
|
|
26
|
+
if (!assetSync.isComplete()) try {
|
|
27
|
+
await assetSync.upload();
|
|
28
|
+
} catch (error) {
|
|
29
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
30
|
+
throw new Error(`Error uploading ${assetSync.label}: ${message}`);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
await assetSync.markSynced();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
36
|
+
throw new Error(`Error marking ${assetSync.label} as synced: ${message}`);
|
|
37
|
+
}
|
|
38
|
+
yield {
|
|
39
|
+
status: "success",
|
|
40
|
+
message: `Synced ${assetSync.label}: ${assetSync.path}`
|
|
41
|
+
};
|
|
42
|
+
return;
|
|
48
43
|
};
|
|
44
|
+
export { doAssetSync };
|
|
@@ -1,82 +1,59 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
1
|
import { getAssetSync } from "./syncAssetsDirectory/SubAssetSync.js";
|
|
4
2
|
import { doAssetSync } from "./syncAssetsDirectory/doAssetSync.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
5
|
const syncAssetDirectory = async (cacheDir) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (error instanceof Error) {
|
|
59
|
-
reportError(subAsset, error.message);
|
|
60
|
-
} else {
|
|
61
|
-
reportError(subAsset, "Unknown error");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (Object.keys(errors).length) {
|
|
67
|
-
process.stderr.write("\n\nā Encountered errors while syncing assets:\n");
|
|
68
|
-
for (const [asset, messages] of Object.entries(errors)) {
|
|
69
|
-
process.stderr.write(`
|
|
70
|
-
š« ${asset}
|
|
71
|
-
`);
|
|
72
|
-
for (const message of messages) {
|
|
73
|
-
process.stderr.write(` - ${message}
|
|
74
|
-
`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
throw new Error("Failed to sync assets");
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
export {
|
|
81
|
-
syncAssetDirectory
|
|
6
|
+
const stat = await fs.stat(cacheDir).catch((error) => {
|
|
7
|
+
if (error.code === "ENOENT") return;
|
|
8
|
+
throw error;
|
|
9
|
+
});
|
|
10
|
+
if (!stat?.isDirectory()) {
|
|
11
|
+
console.error(`No assets cache directory found at ${cacheDir}`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const assets = await fs.readdir(cacheDir);
|
|
15
|
+
process.stderr.write(`Syncing asset dir: ${cacheDir}\n`);
|
|
16
|
+
const errors = {};
|
|
17
|
+
const reportError = (path$1, message) => {
|
|
18
|
+
errors[path$1] ||= [];
|
|
19
|
+
errors[path$1].push(message);
|
|
20
|
+
process.stderr.write(` š« ${message}\n`);
|
|
21
|
+
};
|
|
22
|
+
const reportSuccess = (_path, message) => {
|
|
23
|
+
process.stderr.write(` ā
${message}\n`);
|
|
24
|
+
};
|
|
25
|
+
const reportInfo = (_path, message) => {
|
|
26
|
+
process.stderr.write(` ${message}\n`);
|
|
27
|
+
};
|
|
28
|
+
for (const assetMd5 of assets) {
|
|
29
|
+
reportInfo(assetMd5, `Syncing asset: ${assetMd5}`);
|
|
30
|
+
const assetDir = path.join(cacheDir, assetMd5);
|
|
31
|
+
const stat$1 = await fs.stat(assetDir);
|
|
32
|
+
if (!stat$1.isDirectory()) {
|
|
33
|
+
reportError(assetMd5, "Invalid asset. Did not find asset directory.");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const subAssets = await fs.readdir(assetDir);
|
|
37
|
+
for (const subAsset of subAssets) {
|
|
38
|
+
if (subAsset.endsWith(".info")) continue;
|
|
39
|
+
const subAssetPath = path.join(assetDir, subAsset);
|
|
40
|
+
try {
|
|
41
|
+
const assetSync = getAssetSync(subAssetPath, assetMd5);
|
|
42
|
+
for await (const { status, message } of doAssetSync(assetSync)) if (status === "success") reportSuccess(subAsset, message);
|
|
43
|
+
else if (status === "info") reportInfo(subAsset, message);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error instanceof Error) reportError(subAsset, error.message);
|
|
46
|
+
else reportError(subAsset, "Unknown error");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (Object.keys(errors).length) {
|
|
51
|
+
process.stderr.write("\n\nā Encountered errors while syncing assets:\n");
|
|
52
|
+
for (const [asset, messages] of Object.entries(errors)) {
|
|
53
|
+
process.stderr.write(`\nš« ${asset}\n`);
|
|
54
|
+
for (const message of messages) process.stderr.write(` - ${message}\n`);
|
|
55
|
+
}
|
|
56
|
+
throw new Error("Failed to sync assets");
|
|
57
|
+
}
|
|
82
58
|
};
|
|
59
|
+
export { syncAssetDirectory };
|
|
@@ -1,82 +1,65 @@
|
|
|
1
1
|
import { Stream } from "node:stream";
|
|
2
2
|
const createReadableStreamFromReadable = (source) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const pump = new StreamPump(source);
|
|
4
|
+
const stream = new ReadableStream(pump, pump);
|
|
5
|
+
return stream;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.stream.resume();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
close() {
|
|
68
|
-
if (this.controller) {
|
|
69
|
-
this.controller.close();
|
|
70
|
-
delete this.controller;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
error(error) {
|
|
74
|
-
if (this.controller) {
|
|
75
|
-
this.controller.error(error);
|
|
76
|
-
delete this.controller;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export {
|
|
81
|
-
createReadableStreamFromReadable
|
|
7
|
+
var StreamPump = class {
|
|
8
|
+
constructor(stream) {
|
|
9
|
+
this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
10
|
+
this.accumalatedSize = 0;
|
|
11
|
+
this.stream = stream;
|
|
12
|
+
this.enqueue = this.enqueue.bind(this);
|
|
13
|
+
this.error = this.error.bind(this);
|
|
14
|
+
this.close = this.close.bind(this);
|
|
15
|
+
}
|
|
16
|
+
size(chunk) {
|
|
17
|
+
return chunk?.byteLength || 0;
|
|
18
|
+
}
|
|
19
|
+
start(controller) {
|
|
20
|
+
this.controller = controller;
|
|
21
|
+
this.stream.on("data", this.enqueue);
|
|
22
|
+
this.stream.once("error", this.error);
|
|
23
|
+
this.stream.once("end", this.close);
|
|
24
|
+
this.stream.once("close", this.close);
|
|
25
|
+
}
|
|
26
|
+
pull() {
|
|
27
|
+
this.resume();
|
|
28
|
+
}
|
|
29
|
+
cancel(reason) {
|
|
30
|
+
if (this.stream.destroy) this.stream.destroy(reason);
|
|
31
|
+
this.stream.off("data", this.enqueue);
|
|
32
|
+
this.stream.off("error", this.error);
|
|
33
|
+
this.stream.off("end", this.close);
|
|
34
|
+
this.stream.off("close", this.close);
|
|
35
|
+
}
|
|
36
|
+
enqueue(chunk) {
|
|
37
|
+
if (this.controller) try {
|
|
38
|
+
const available = (this.controller.desiredSize || 0) - chunk.length;
|
|
39
|
+
this.controller.enqueue(chunk);
|
|
40
|
+
if (available <= 0) this.pause();
|
|
41
|
+
} catch (_error) {
|
|
42
|
+
this.controller.error(/* @__PURE__ */ new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
|
|
43
|
+
this.cancel();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
pause() {
|
|
47
|
+
if (this.stream.pause) this.stream.pause();
|
|
48
|
+
}
|
|
49
|
+
resume() {
|
|
50
|
+
if (this.stream.readable && this.stream.resume) this.stream.resume();
|
|
51
|
+
}
|
|
52
|
+
close() {
|
|
53
|
+
if (this.controller) {
|
|
54
|
+
this.controller.close();
|
|
55
|
+
delete this.controller;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
error(error) {
|
|
59
|
+
if (this.controller) {
|
|
60
|
+
this.controller.error(error);
|
|
61
|
+
delete this.controller;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
82
64
|
};
|
|
65
|
+
export { createReadableStreamFromReadable };
|