@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.
- package/init/index.js +29 -21
- 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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|