diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-07-08 15:38:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-08 09:38:22 -0400 |
commit | 231899695d410d8d8c14c0936682a90e98bc6fd3 (patch) | |
tree | 4703344ac42cfdee4344e55e71824fb1743b4ff1 /cli/js/write_text_file.ts | |
parent | 82aabb657a8fbaf107e58214490fdd129db3ae6b (diff) |
feat(cli): Add WriteFileOptions to writeTextFile & writeTextFileSync (#6280)
Diffstat (limited to 'cli/js/write_text_file.ts')
-rw-r--r-- | cli/js/write_text_file.ts | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/cli/js/write_text_file.ts b/cli/js/write_text_file.ts index 615813460..ca7646c75 100644 --- a/cli/js/write_text_file.ts +++ b/cli/js/write_text_file.ts @@ -1,23 +1,20 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { writeFileSync, writeFile, WriteFileOptions } from "./write_file.ts"; -import { open, openSync } from "./files.ts"; -import { writeAll, writeAllSync } from "./buffer.ts"; - -export function writeTextFileSync(path: string | URL, data: string): void { - const file = openSync(path, { write: true, create: true, truncate: true }); +export function writeTextFileSync( + path: string | URL, + data: string, + options: WriteFileOptions = {} +): void { const encoder = new TextEncoder(); - const contents = encoder.encode(data); - writeAllSync(file, contents); - file.close(); + return writeFileSync(path, encoder.encode(data), options); } -export async function writeTextFile( +export function writeTextFile( path: string | URL, - data: string + data: string, + options: WriteFileOptions = {} ): Promise<void> { - const file = await open(path, { write: true, create: true, truncate: true }); const encoder = new TextEncoder(); - const contents = encoder.encode(data); - await writeAll(file, contents); - file.close(); + return writeFile(path, encoder.encode(data), options); } |