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_common.ts | |
parent | aeadf8189ae25d1b43f3c538a6c4aa6e5380c974 (diff) |
feat(std/node): support hex/base64 encoding in fs.readFile/fs.writeFile (#6512)
Diffstat (limited to 'std/node/_fs/_fs_common.ts')
-rw-r--r-- | std/node/_fs/_fs_common.ts | 17 |
1 files changed, 7 insertions, 10 deletions
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`); } |