@codearcade/subtitle-generator 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/init/index.js +29 -21
  2. package/package.json +1 -1
package/init/index.js CHANGED
@@ -47,27 +47,35 @@ const init = async () => {
47
47
 
48
48
  const file = fs.createWriteStream(dest);
49
49
 
50
- await res.body.pipeTo(
51
- new WritableStream({
52
- write(chunk) {
53
- downloaded += chunk.length;
54
- if (total) {
55
- const percent = ((downloaded / total) * 100).toFixed(2);
56
- process.stdout.write(`Downloading ${label}... ${percent}%\r`);
57
- } else {
58
- process.stdout.write(`Downloaded ${downloaded} bytes\r`);
59
- }
60
- file.write(chunk);
61
- },
62
- close() {
63
- file.end();
64
- console.log(`\n${label} download complete.`);
65
- },
66
- abort(err) {
67
- file.destroy(err);
68
- },
69
- }),
70
- );
50
+ // Wait for both the pipeTo AND the file stream to fully close
51
+ // so the file handle is released before we try to use the file.
52
+ await new Promise((resolve, reject) => {
53
+ file.on("close", resolve);
54
+ file.on("error", reject);
55
+
56
+ res.body.pipeTo(
57
+ new WritableStream({
58
+ write(chunk) {
59
+ downloaded += chunk.length;
60
+ if (total) {
61
+ const percent = ((downloaded / total) * 100).toFixed(2);
62
+ process.stdout.write(`Downloading ${label}... ${percent}%\r`);
63
+ } else {
64
+ process.stdout.write(`Downloaded ${downloaded} bytes\r`);
65
+ }
66
+ file.write(chunk);
67
+ },
68
+ close() {
69
+ file.end(); // triggers 'close' event on the file stream once flushed
70
+ console.log(`\n${label} download complete.`);
71
+ },
72
+ abort(err) {
73
+ file.destroy(err);
74
+ reject(err);
75
+ },
76
+ }),
77
+ ).catch(reject);
78
+ });
71
79
  }
72
80
 
73
81
  // 1. Download the AI Model
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codearcade/subtitle-generator",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",