@miso.ai/server-commons 0.6.5-beta.7 → 0.6.5-beta.8
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 +1 -1
- package/src/file.js +22 -1
- package/src/sink/bps.js +1 -1
- package/src/store.js +2 -2
package/package.json
CHANGED
package/src/file.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { access } from 'fs/promises';
|
|
2
|
-
import { accessSync, constants } from 'fs';
|
|
2
|
+
import { accessSync, constants, createReadStream } from 'fs';
|
|
3
|
+
import { createInterface } from 'readline';
|
|
3
4
|
|
|
4
5
|
export async function fileExists(file, mode = constants.F_OK) {
|
|
5
6
|
try {
|
|
@@ -18,3 +19,23 @@ export function fileExistsSync(file, mode = constants.F_OK) {
|
|
|
18
19
|
return false;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
22
|
+
|
|
23
|
+
export async function readFileAsLines(file) {
|
|
24
|
+
const fileStream = createReadStream(file, { encoding: 'utf8' });
|
|
25
|
+
const rl = createInterface({
|
|
26
|
+
input: fileStream,
|
|
27
|
+
crlfDelay: Infinity
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const lines = [];
|
|
31
|
+
for await (const line of rl) {
|
|
32
|
+
const trimmed = line.trim();
|
|
33
|
+
if (trimmed) {
|
|
34
|
+
lines.push(trimmed);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
rl.close();
|
|
39
|
+
|
|
40
|
+
return lines;
|
|
41
|
+
}
|
package/src/sink/bps.js
CHANGED
package/src/store.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import { Transform } from 'stream';
|
|
4
|
+
import { readFileAsLines } from './file.js';
|
|
4
5
|
|
|
5
6
|
const DEFAULT_FLUSH_THRESHOLD = 100;
|
|
6
7
|
|
|
@@ -88,8 +89,7 @@ export default class HashStore {
|
|
|
88
89
|
|
|
89
90
|
async _read() {
|
|
90
91
|
try {
|
|
91
|
-
|
|
92
|
-
return content.split('\n').map(v => v.trim()).filter(v => v);
|
|
92
|
+
return await readFileAsLines(this._file);
|
|
93
93
|
} catch (err) {
|
|
94
94
|
if (err.code !== 'ENOENT') {
|
|
95
95
|
throw err;
|