From a216bd06fc7dfb4a136e9fc04ae119c2e4801b6e Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Sat, 27 Jun 2020 22:52:49 +0200 Subject: feat(std/node): support hex/base64 encoding in fs.readFile/fs.writeFile (#6512) --- std/node/_fs/_fs_writeFile.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'std/node/_fs/_fs_writeFile.ts') 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; -- cgit v1.2.3