diff options
author | Ali Hasani <a.hassssani@gmail.com> | 2020-05-03 23:44:38 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-03 15:14:38 -0400 |
commit | 5cc0f056d1af6f76c6ad81a6cd68dcaabba60f35 (patch) | |
tree | 4a32cb418ca84aba47e05e6dc6c98e8ef724fcd0 /std/node/_fs/_fs_appendFile.ts | |
parent | 7e32269f3f230c5b714bbf70aa59d74f9a867373 (diff) |
[std/node] add the ability to path argument to be URL type (#5055)
Diffstat (limited to 'std/node/_fs/_fs_appendFile.ts')
-rw-r--r-- | std/node/_fs/_fs_appendFile.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/std/node/_fs/_fs_appendFile.ts b/std/node/_fs/_fs_appendFile.ts index 48b05ff80..b116589a0 100644 --- a/std/node/_fs/_fs_appendFile.ts +++ b/std/node/_fs/_fs_appendFile.ts @@ -1,17 +1,19 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { FileOptions, isFileOptions, CallbackWithError } from "./_fs_common.ts"; import { notImplemented } from "../_utils.ts"; +import { fromFileUrl } from "../path.ts"; /** - * TODO: Also accept 'data' parameter as a Node polyfill Buffer or URL type once these + * TODO: Also accept 'data' parameter as a Node polyfill Buffer type once these * are implemented. See https://github.com/denoland/deno/issues/3403 */ export function appendFile( - pathOrRid: string | number, + pathOrRid: string | number | URL, data: string, optionsOrCallback: string | FileOptions | CallbackWithError, callback?: CallbackWithError ): void { + pathOrRid = pathOrRid instanceof URL ? fromFileUrl(pathOrRid) : pathOrRid; const callbackFn: CallbackWithError | undefined = optionsOrCallback instanceof Function ? optionsOrCallback : callback; const options: string | FileOptions | undefined = @@ -39,7 +41,7 @@ export function appendFile( //TODO rework once https://github.com/denoland/deno/issues/4017 completes notImplemented("Deno does not yet support setting mode on create"); } - Deno.open(pathOrRid, getOpenOptions(flag)) + Deno.open(pathOrRid as string, getOpenOptions(flag)) .then(({ rid: openedFileRid }) => { rid = openedFileRid; return Deno.write(openedFileRid, buffer); @@ -66,17 +68,18 @@ function closeRidIfNecessary(isPathString: boolean, rid: number): void { } /** - * TODO: Also accept 'data' parameter as a Node polyfill Buffer or URL type once these + * TODO: Also accept 'data' parameter as a Node polyfill Buffer type once these * are implemented. See https://github.com/denoland/deno/issues/3403 */ export function appendFileSync( - pathOrRid: string | number, + pathOrRid: string | number | URL, data: string, options?: string | FileOptions ): void { let rid = -1; validateEncoding(options); + pathOrRid = pathOrRid instanceof URL ? fromFileUrl(pathOrRid) : pathOrRid; try { if (typeof pathOrRid === "number") { |