diff options
| author | ali ahmed <48116123+AliBasicCoder@users.noreply.github.com> | 2020-10-06 07:26:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-06 01:26:12 -0400 |
| commit | a51408a4bc1621d27241377ac1662944d8c14fc0 (patch) | |
| tree | 7f68ecefacdace52c3108435d1235c3be33b3221 /std/node/_fs/_fs_appendFile.ts | |
| parent | d0f734bacc269b5e998ee30a7c87bbf15d5a86be (diff) | |
fix(std/node/fs): allow appendFileSync to accept Uint8Array as type for data (#7835)
Diffstat (limited to 'std/node/_fs/_fs_appendFile.ts')
| -rw-r--r-- | std/node/_fs/_fs_appendFile.ts | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/std/node/_fs/_fs_appendFile.ts b/std/node/_fs/_fs_appendFile.ts index cb51def67..b7fce274f 100644 --- a/std/node/_fs/_fs_appendFile.ts +++ b/std/node/_fs/_fs_appendFile.ts @@ -15,7 +15,7 @@ import { fromFileUrl } from "../path.ts"; */ export function appendFile( pathOrRid: string | number | URL, - data: string, + data: string | Uint8Array, optionsOrCallback: Encodings | WriteFileOptions | CallbackWithError, callback?: CallbackWithError, ): void { @@ -30,7 +30,9 @@ export function appendFile( validateEncoding(options); let rid = -1; - const buffer: Uint8Array = new TextEncoder().encode(data); + const buffer: Uint8Array = data instanceof Uint8Array + ? data + : new TextEncoder().encode(data); new Promise((resolve, reject) => { if (typeof pathOrRid === "number") { rid = pathOrRid; @@ -79,7 +81,7 @@ function closeRidIfNecessary(isPathString: boolean, rid: number): void { */ export function appendFileSync( pathOrRid: string | number | URL, - data: string, + data: string | Uint8Array, options?: Encodings | WriteFileOptions, ): void { let rid = -1; @@ -107,7 +109,9 @@ export function appendFileSync( rid = file.rid; } - const buffer: Uint8Array = new TextEncoder().encode(data); + const buffer: Uint8Array = data instanceof Uint8Array + ? data + : new TextEncoder().encode(data); Deno.writeSync(rid, buffer); } finally { |
