@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.
Files changed (36) hide show
  1. package/dist/VERSION.d.ts +1 -1
  2. package/dist/VERSION.js +2 -4
  3. package/dist/commands/auth.js +16 -25
  4. package/dist/commands/check.js +81 -108
  5. package/dist/commands/mux.d.ts +1 -0
  6. package/dist/commands/preview.js +4 -1
  7. package/dist/commands/process-file.js +18 -34
  8. package/dist/commands/process.js +28 -31
  9. package/dist/commands/render.js +117 -157
  10. package/dist/commands/sync.js +3 -5
  11. package/dist/commands/webhook.js +48 -52
  12. package/dist/index.js +3 -7
  13. package/dist/operations/processRenderInfo.js +25 -31
  14. package/dist/operations/syncAssetsDirectory/SubAssetSync.js +11 -18
  15. package/dist/operations/syncAssetsDirectory/SyncCaption.js +46 -73
  16. package/dist/operations/syncAssetsDirectory/SyncFragmentIndex.js +53 -83
  17. package/dist/operations/syncAssetsDirectory/SyncImage.js +72 -99
  18. package/dist/operations/syncAssetsDirectory/SyncStatus.js +30 -37
  19. package/dist/operations/syncAssetsDirectory/SyncTrack.js +107 -143
  20. package/dist/operations/syncAssetsDirectory/doAssetSync.js +42 -46
  21. package/dist/operations/syncAssetsDirectory.js +55 -78
  22. package/dist/utils/createReadableStreamFromReadable.js +61 -78
  23. package/dist/utils/index.js +10 -16
  24. package/dist/utils/launchBrowserAndWaitForSDK.js +31 -43
  25. package/dist/utils/startDevServer.d.ts +1 -1
  26. package/dist/utils/startPreviewServer.d.ts +1 -1
  27. package/dist/utils/startPreviewServer.js +28 -34
  28. package/dist/utils/validateVideoResolution.js +19 -23
  29. package/dist/utils/withSpinner.js +10 -12
  30. package/package.json +8 -8
  31. package/src/commands/check.ts +2 -2
  32. package/src/commands/mux.ts +10 -0
  33. package/src/utils/createReadableStreamFromReadable.ts +3 -7
  34. package/src/utils/startDevServer.ts +5 -5
  35. package/src/utils/startPreviewServer.ts +1 -1
  36. 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
- class SyncTrack {
10
- constructor(path, md5) {
11
- this.path = path;
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) {
23
- return this._isoFile;
24
- }
25
- throw new Error("ISOBMFF file not found. Call prepare() first.");
26
- }
27
- async byteSize() {
28
- return (await fs.stat(this.path)).size;
29
- }
30
- get probeResult() {
31
- if (this._probeResult) {
32
- return this._probeResult;
33
- }
34
- throw new Error("Probe result not found. Call prepare() first.");
35
- }
36
- get track() {
37
- const [track] = this.probeResult.streams;
38
- if (track) {
39
- return track;
40
- }
41
- throw new Error(`No track found in track: ${this.path}`);
42
- }
43
- async prepare() {
44
- const maybeIsoFile = await lookupISOBMFFFileByMd5(getClient(), this.md5);
45
- if (maybeIsoFile) {
46
- this._isoFile = maybeIsoFile;
47
- } else {
48
- this._isoFile = await createISOBMFFFile(getClient(), {
49
- md5: this.md5,
50
- filename: basename(this.path).replace(/\.track-[\d]+.mp4$/, "")
51
- });
52
- }
53
- this._probeResult = await Probe.probePath(this.path);
54
- }
55
- get trackId() {
56
- const trackId = this.path.match(/track-([\d]+).mp4/)?.[1];
57
- if (!trackId) {
58
- throw new Error(`No track ID found for track: ${this.path}`);
59
- }
60
- return trackId;
61
- }
62
- get trackDuration() {
63
- const track = this.track;
64
- if (!track.duration) {
65
- throw new Error(`No duration found in track: ${this.path}`);
66
- }
67
- if (typeof track.duration === "string") {
68
- return Number.parseFloat(track.duration);
69
- }
70
- return track.duration;
71
- }
72
- async validate() {
73
- this.trackId;
74
- this.isoFile;
75
- this.trackDuration;
76
- }
77
- async create() {
78
- const track = this.track;
79
- const isoFile = this.isoFile;
80
- if (track.codec_type === "data") {
81
- throw new Error(`Unsupported codec type: ${track.codec_type}`);
82
- }
83
- const createPayload = track.codec_type === "audio" ? {
84
- type: track.codec_type,
85
- file_id: isoFile.id,
86
- track_id: Number(this.trackId),
87
- probe_info: track,
88
- duration_ms: Math.round(this.trackDuration * 1e3),
89
- codec_name: track.codec_name,
90
- byte_size: await this.byteSize()
91
- } : {
92
- type: track.codec_type,
93
- file_id: isoFile.id,
94
- track_id: Number(this.trackId),
95
- probe_info: track,
96
- duration_ms: Math.round(this.trackDuration * 1e3),
97
- codec_name: track.codec_name,
98
- byte_size: await this.byteSize()
99
- };
100
- this.created = await createISOBMFFTrack(getClient(), createPayload);
101
- }
102
- isComplete() {
103
- return !!this.created?.complete;
104
- }
105
- async upload() {
106
- if (!this.created) {
107
- throw new Error(
108
- "Track not created. Should have been prevented by .isComplete()"
109
- );
110
- }
111
- await uploadISOBMFFTrack(
112
- getClient(),
113
- this.isoFile.id,
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
- 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()) {
27
- try {
28
- await assetSync.upload();
29
- } catch (error) {
30
- const message = error instanceof Error ? error.message : "Unknown error";
31
- throw new Error(`Error uploading ${assetSync.label}: ${message}`);
32
- }
33
- }
34
- try {
35
- await assetSync.markSynced();
36
- } catch (error) {
37
- const message = error instanceof Error ? error.message : "Unknown error";
38
- throw new Error(`Error marking ${assetSync.label} as synced: ${message}`);
39
- }
40
- yield {
41
- status: "success",
42
- message: `Synced ${assetSync.label}: ${assetSync.path}`
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
- const stat = await fs.stat(cacheDir).catch((error) => {
7
- if (error.code === "ENOENT") {
8
- return;
9
- }
10
- throw error;
11
- });
12
- if (!stat?.isDirectory()) {
13
- console.error(`No assets cache directory found at ${cacheDir}`);
14
- return;
15
- }
16
- const assets = await fs.readdir(cacheDir);
17
- process.stderr.write(`Syncing asset dir: ${cacheDir}
18
- `);
19
- const errors = {};
20
- const reportError = (path2, message) => {
21
- errors[path2] ||= [];
22
- errors[path2].push(message);
23
- process.stderr.write(` 🚫 ${message}
24
- `);
25
- };
26
- const reportSuccess = (_path, message) => {
27
- process.stderr.write(` āœ… ${message}
28
- `);
29
- };
30
- const reportInfo = (_path, message) => {
31
- process.stderr.write(` ${message}
32
- `);
33
- };
34
- for (const assetMd5 of assets) {
35
- reportInfo(assetMd5, `Syncing asset: ${assetMd5}`);
36
- const assetDir = path.join(cacheDir, assetMd5);
37
- const stat2 = await fs.stat(assetDir);
38
- if (!stat2.isDirectory()) {
39
- reportError(assetMd5, "Invalid asset. Did not find asset directory.");
40
- return;
41
- }
42
- const subAssets = await fs.readdir(assetDir);
43
- for (const subAsset of subAssets) {
44
- if (subAsset.endsWith(".info")) {
45
- continue;
46
- }
47
- const subAssetPath = path.join(assetDir, subAsset);
48
- try {
49
- const assetSync = getAssetSync(subAssetPath, assetMd5);
50
- for await (const { status, message } of doAssetSync(assetSync)) {
51
- if (status === "success") {
52
- reportSuccess(subAsset, message);
53
- } else if (status === "info") {
54
- reportInfo(subAsset, message);
55
- }
56
- }
57
- } catch (error) {
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
- const pump = new StreamPump(source);
4
- const stream = new ReadableStream(pump, pump);
5
- return stream;
3
+ const pump = new StreamPump(source);
4
+ const stream = new ReadableStream(pump, pump);
5
+ return stream;
6
6
  };
7
- class StreamPump {
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) {
31
- this.stream.destroy(reason);
32
- }
33
- this.stream.off("data", this.enqueue);
34
- this.stream.off("error", this.error);
35
- this.stream.off("end", this.close);
36
- this.stream.off("close", this.close);
37
- }
38
- enqueue(chunk) {
39
- if (this.controller) {
40
- try {
41
- const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
42
- const available = (this.controller.desiredSize || 0) - bytes.byteLength;
43
- this.controller.enqueue(bytes);
44
- if (available <= 0) {
45
- this.pause();
46
- }
47
- } catch (error) {
48
- this.controller.error(
49
- new Error(
50
- "Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"
51
- )
52
- );
53
- this.cancel();
54
- }
55
- }
56
- }
57
- pause() {
58
- if (this.stream.pause) {
59
- this.stream.pause();
60
- }
61
- }
62
- resume() {
63
- if (this.stream.readable && this.stream.resume) {
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 };