clean up code in cli/js (#6611)

This commit is contained in:
Stanislav 2020-07-07 04:45:39 +03:00 committed by GitHub
parent ab4c574f52
commit 158ae0bfe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
89 changed files with 395 additions and 354 deletions

View file

@ -1,10 +1,12 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
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 });
const enc = new TextEncoder();
const contents = enc.encode(data);
const encoder = new TextEncoder();
const contents = encoder.encode(data);
writeAllSync(file, contents);
file.close();
}
@ -14,8 +16,8 @@ export async function writeTextFile(
data: string
): Promise<void> {
const file = await open(path, { write: true, create: true, truncate: true });
const enc = new TextEncoder();
const contents = enc.encode(data);
const encoder = new TextEncoder();
const contents = encoder.encode(data);
await writeAll(file, contents);
file.close();
}