2020-04-28 01:35:20 -04:00
|
|
|
import { open, openSync } from "./files.ts";
|
|
|
|
import { writeAll, writeAllSync } from "./buffer.ts";
|
|
|
|
|
2020-06-11 12:36:20 -04:00
|
|
|
export function writeTextFileSync(path: string | URL, data: string): void {
|
2020-04-28 01:35:20 -04:00
|
|
|
const file = openSync(path, { write: true, create: true, truncate: true });
|
|
|
|
const enc = new TextEncoder();
|
|
|
|
const contents = enc.encode(data);
|
|
|
|
writeAllSync(file, contents);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2020-06-11 12:36:20 -04:00
|
|
|
export async function writeTextFile(
|
|
|
|
path: string | URL,
|
|
|
|
data: string
|
|
|
|
): Promise<void> {
|
2020-04-28 01:35:20 -04:00
|
|
|
const file = await open(path, { write: true, create: true, truncate: true });
|
|
|
|
const enc = new TextEncoder();
|
|
|
|
const contents = enc.encode(data);
|
|
|
|
await writeAll(file, contents);
|
|
|
|
file.close();
|
|
|
|
}
|