mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 16:49:18 -05:00
18 lines
652 B
TypeScript
18 lines
652 B
TypeScript
import { open, openSync } from "./files.ts";
|
|
import { writeAll, writeAllSync } from "./buffer.ts";
|
|
|
|
export function writeTextFileSync(path: string, data: string): void {
|
|
const file = openSync(path, { write: true, create: true, truncate: true });
|
|
const enc = new TextEncoder();
|
|
const contents = enc.encode(data);
|
|
writeAllSync(file, contents);
|
|
file.close();
|
|
}
|
|
|
|
export async function writeTextFile(path: string, data: string): Promise<void> {
|
|
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();
|
|
}
|