diff options
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") { |