summaryrefslogtreecommitdiff
path: root/std/node/_fs/_fs_writeFile.ts
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-05-23 04:11:10 +0200
committerGitHub <noreply@github.com>2020-05-22 22:11:10 -0400
commit7f81f02ce794ac14ca25d3505f339cb663499ce6 (patch)
tree3e84ef5d0b92315aebdf1f4d48439d507ce5bfae /std/node/_fs/_fs_writeFile.ts
parent28b651c2e2bbe590295077f9253a3feb084349fd (diff)
std/node: fs.writeFile/sync path can now be an URL (#5652)
Diffstat (limited to 'std/node/_fs/_fs_writeFile.ts')
-rw-r--r--std/node/_fs/_fs_writeFile.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/std/node/_fs/_fs_writeFile.ts b/std/node/_fs/_fs_writeFile.ts
index b46620d9b..72e75c97a 100644
--- a/std/node/_fs/_fs_writeFile.ts
+++ b/std/node/_fs/_fs_writeFile.ts
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { notImplemented } from "../_utils.ts";
+import { fromFileUrl } from "../path.ts";
import {
WriteFileOptions,
@@ -10,7 +11,7 @@ import {
} from "./_fs_common.ts";
export function writeFile(
- pathOrRid: string | number,
+ pathOrRid: string | number | URL,
data: string | Uint8Array,
optOrCallback: string | CallbackWithError | WriteFileOptions | undefined,
callback?: CallbackWithError
@@ -24,6 +25,8 @@ export function writeFile(
throw new TypeError("Callback must be a function.");
}
+ pathOrRid = pathOrRid instanceof URL ? fromFileUrl(pathOrRid) : pathOrRid;
+
const flag: string | undefined = isFileOptions(options)
? options.flag
: undefined;
@@ -65,10 +68,12 @@ export function writeFile(
}
export function writeFileSync(
- pathOrRid: string | number,
+ pathOrRid: string | number | URL,
data: string | Uint8Array,
options?: string | WriteFileOptions
): void {
+ pathOrRid = pathOrRid instanceof URL ? fromFileUrl(pathOrRid) : pathOrRid;
+
const flag: string | undefined = isFileOptions(options)
? options.flag
: undefined;