From: Ardis Lu Date: Sat, 11 Jan 2025 09:33:42 +0000 (-0800) Subject: Make file URL parser more robust X-Git-Tag: v0.1.0~126 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=7c8f52a3c6c46042f305cfdd478f39c4d1d1b7ae;p=csvio Make file URL parser more robust --- diff --git a/src/core.js b/src/core.js index bf05749..b9d324e 100644 --- a/src/core.js +++ b/src/core.js @@ -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;