]> git.ardis.lu - csvio/commitdiff
Make file URL parser more robust
authorArdis Lu <ardisglu@gmail.com>
Sat, 11 Jan 2025 09:33:42 +0000 (01:33 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sat, 11 Jan 2025 09:33:42 +0000 (01:33 -0800)
src/core.js

index bf057497e32ecc14467166ea530a68018e647d79..b9d324e2473dfeafe22300e0373aad85c3b9a56a 100644 (file)
@@ -1,5 +1,6 @@
 import { createReadStream } from 'node:fs';
 import { mkdir, open } from 'node:fs/promises';
+import { platform } from 'node:os';
 import { dirname, normalize } from 'node:path';
 import { Readable } from 'node:stream';
 /** @import { PathLike } from 'node:fs' */
@@ -185,7 +186,12 @@ export function createCSVWritableStream(path) {
     fullPath = normalize(new TextDecoder().decode(path));
   }
   else { // Assuming URL
-    fullPath = normalize(path.pathname.substring(1));
+    if (platform() === 'win32' && path.pathname.startsWith('/')) {
+      fullPath = normalize(decodeURIComponent(path.pathname.substring(1)));
+    }
+    else {
+      fullPath = normalize(decodeURIComponent(path.pathname));
+    }
   }
   const dir = dirname(fullPath);
   let handle;
This page took 0.038346 seconds and 4 git commands to generate.