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_common.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'std/node/_fs/_fs_common.ts') diff --git a/std/node/_fs/_fs_common.ts b/std/node/_fs/_fs_common.ts index 43d3b8064..3c20ca73e 100644 --- a/std/node/_fs/_fs_common.ts +++ b/std/node/_fs/_fs_common.ts @@ -61,7 +61,11 @@ export function getEncoding( export function checkEncoding(encoding: Encodings | null): Encodings | null { if (!encoding) return null; - if (encoding === "utf8" || encoding === "utf-8") { + + encoding = encoding.toLowerCase() as Encodings; + if (["utf8", "hex", "base64"].includes(encoding)) return encoding; + + if (encoding === "utf-8") { return "utf8"; } if (encoding === "binary") { @@ -70,16 +74,9 @@ export function checkEncoding(encoding: Encodings | null): Encodings | null { // node -e "require('fs').readFile('../world.txt', 'buffer', console.log)" } - const notImplementedEncodings = [ - "utf16le", - "latin1", - "base64", - "hex", - "ascii", - "ucs2", - ]; + const notImplementedEncodings = ["utf16le", "latin1", "ascii", "ucs2"]; - if (notImplementedEncodings.includes(encoding)) { + if (notImplementedEncodings.includes(encoding as string)) { notImplemented(`"${encoding}" encoding`); } -- cgit v1.2.3