2020-07-07 04:45:39 +03:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2020-04-28 00:35:20 -05:00
|
|
|
import { open, openSync } from "./files.ts";
|
|
|
|
import { writeAll, writeAllSync } from "./buffer.ts";
|
|
|
|
|
2020-06-12 02:36:20 +10:00
|
|
|
export function writeTextFileSync(path: string | URL, data: string): void {
|
2020-04-28 00:35:20 -05:00
|
|
|
const file = openSync(path, { write: true, create: true, truncate: true });
|
2020-07-07 04:45:39 +03:00
|
|
|
const encoder = new TextEncoder();
|
|
|
|
const contents = encoder.encode(data);
|
2020-04-28 00:35:20 -05:00
|
|
|
writeAllSync(file, contents);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2020-06-12 02:36:20 +10:00
|
|
|
export async function writeTextFile(
|
|
|
|
path: string | URL,
|
|
|
|
data: string
|
|
|
|
): Promise<void> {
|
2020-04-28 00:35:20 -05:00
|
|
|
const file = await open(path, { write: true, create: true, truncate: true });
|
2020-07-07 04:45:39 +03:00
|
|
|
const encoder = new TextEncoder();
|
|
|
|
const contents = encoder.encode(data);
|
2020-04-28 00:35:20 -05:00
|
|
|
await writeAll(file, contents);
|
|
|
|
file.close();
|
|
|
|
}
|