@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 CHANGED
@@ -21,5 +21,5 @@
21
21
  "uuid": "^9.0.0",
22
22
  "yargs": "^17.5.1"
23
23
  },
24
- "version": "0.6.5-beta.7"
24
+ "version": "0.6.5-beta.8"
25
25
  }
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
@@ -12,7 +12,7 @@ export default class BpsSink {
12
12
 
13
13
  _normalizeOptions({
14
14
  recordsPerSecord = 100000,
15
- bytesPerSecond = 10 * 1024 * 1024,
15
+ bytesPerSecond = 100 * 1024 * 1024,
16
16
  ...options
17
17
  } = {}) {
18
18
  return {
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
- const content = await fs.readFile(this._file, 'utf-8');
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;