Selaa lähdekoodia

A better way to read local files.

Eugene Lazutkin 3 vuotta sitten
vanhempi
commit
bee28d0c64
2 muutettua tiedostoa jossa 10 lisäystä ja 2 poistoa
  1. 5 1
      tests/test-jsonl-parser.mjs
  2. 5 1
      tests/test-jsonl-parserStream.mjs

+ 5 - 1
tests/test-jsonl-parser.mjs

@@ -63,7 +63,11 @@ for (let i = 1; i <= 12; ++i) {
 
 test.asPromise('jsonl parser: read file', (t, resolve) => {
   if (!/^file:\/\//.test(import.meta.url)) throw Error('Cannot get the current working directory');
-  const fileName = path.join(path.dirname(import.meta.url.substring(7)), './data/sample.jsonl.gz');
+  const isWindows = path.sep === '\\',
+    fileName = path.join(
+      path.dirname(import.meta.url.substring(isWindows ? 8 : 7)),
+      './data/sample.jsonl.gz'
+    );
   let count = 0;
   chain([
     fs.createReadStream(fileName),

+ 5 - 1
tests/test-jsonl-parserStream.mjs

@@ -65,7 +65,11 @@ for (let i = 1; i <= 12; ++i) {
 
 test.asPromise('jsonl parserStream: read file', (t, resolve) => {
   if (!/^file:\/\//.test(import.meta.url)) throw Error('Cannot get the current working directory');
-  const fileName = path.join(path.dirname(import.meta.url.substring(7)), './data/sample.jsonl.gz');
+  const isWindows = path.sep === '\\',
+    fileName = path.join(
+      path.dirname(import.meta.url.substring(isWindows ? 8 : 7)),
+      './data/sample.jsonl.gz'
+    );
   let count = 0;
   fs.createReadStream(fileName)
     .pipe(zlib.createGunzip())