ai-gains 1.5.0 → 1.5.1
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/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const fs = require('fs');
|
|
3
|
+
const readline = require('readline');
|
|
3
4
|
|
|
4
5
|
const transcriptPath = process.argv[2];
|
|
5
6
|
if (!transcriptPath) {
|
|
@@ -8,12 +9,10 @@ if (!transcriptPath) {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const CHUNK_SIZE = 4096;
|
|
11
|
-
const fd = fs.openSync(transcriptPath, 'r');
|
|
12
|
-
const { size } = fs.fstatSync(fd);
|
|
13
12
|
|
|
14
|
-
// Scan from the start for the first entry with a timestamp
|
|
13
|
+
// Scan from the start for the first entry with a top-level timestamp
|
|
15
14
|
function findFirstTimestamp() {
|
|
16
|
-
const rl =
|
|
15
|
+
const rl = readline.createInterface({
|
|
17
16
|
input: fs.createReadStream(transcriptPath),
|
|
18
17
|
crlfDelay: Infinity
|
|
19
18
|
});
|
|
@@ -23,8 +22,8 @@ function findFirstTimestamp() {
|
|
|
23
22
|
try {
|
|
24
23
|
const entry = JSON.parse(line);
|
|
25
24
|
if (entry.timestamp) {
|
|
26
|
-
rl.close();
|
|
27
25
|
resolve(entry.timestamp);
|
|
26
|
+
rl.close();
|
|
28
27
|
}
|
|
29
28
|
} catch {}
|
|
30
29
|
});
|
|
@@ -32,8 +31,10 @@ function findFirstTimestamp() {
|
|
|
32
31
|
});
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
// Scan from the end for the last entry with a timestamp
|
|
34
|
+
// Scan from the end for the last entry with a top-level timestamp
|
|
36
35
|
function findLastTimestamp() {
|
|
36
|
+
const fd = fs.openSync(transcriptPath, 'r');
|
|
37
|
+
const { size } = fs.fstatSync(fd);
|
|
37
38
|
let offset = size;
|
|
38
39
|
let remainder = '';
|
|
39
40
|
let lastTimestamp = null;
|
|
@@ -66,10 +67,8 @@ function findLastTimestamp() {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
(async () => {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
Promise.resolve(findLastTimestamp())
|
|
72
|
-
]);
|
|
70
|
+
const start_time = await findFirstTimestamp();
|
|
71
|
+
const end_time = findLastTimestamp();
|
|
73
72
|
|
|
74
73
|
if (!start_time || !end_time) {
|
|
75
74
|
console.error('Could not extract timestamps from transcript');
|