diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-27 22:52:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-27 16:52:49 -0400 |
commit | a216bd06fc7dfb4a136e9fc04ae119c2e4801b6e (patch) | |
tree | 579124aac7f7e5d11ae585839ef9a752c87f8085 /std/node/_fs/_fs_writeFile.ts | |
parent | aeadf8189ae25d1b43f3c538a6c4aa6e5380c974 (diff) |
feat(std/node): support hex/base64 encoding in fs.readFile/fs.writeFile (#6512)
Diffstat (limited to 'std/node/_fs/_fs_writeFile.ts')
-rw-r--r-- | std/node/_fs/_fs_writeFile.ts | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/std/node/_fs/_fs_writeFile.ts b/std/node/_fs/_fs_writeFile.ts index 54bdb801c..8a66f3f3d 100644 --- a/std/node/_fs/_fs_writeFile.ts +++ b/std/node/_fs/_fs_writeFile.ts @@ -1,6 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { notImplemented } from "../_utils.ts"; import { fromFileUrl } from "../path.ts"; +import { Buffer } from "../buffer.ts"; import { Encodings, @@ -40,8 +41,7 @@ export function writeFile( const encoding = checkEncoding(getEncoding(options)) || "utf8"; const openOptions = getOpenOptions(flag || "w"); - if (typeof data === "string" && encoding === "utf8") - data = new TextEncoder().encode(data) as Uint8Array; + if (typeof data === "string") data = Buffer.from(data, encoding); const isRid = typeof pathOrRid === "number"; let file; @@ -87,8 +87,7 @@ export function writeFileSync( const encoding = checkEncoding(getEncoding(options)) || "utf8"; const openOptions = getOpenOptions(flag || "w"); - if (typeof data === "string" && encoding === "utf8") - data = new TextEncoder().encode(data) as Uint8Array; + if (typeof data === "string") data = Buffer.from(data, encoding); const isRid = typeof pathOrRid === "number"; let file; |