Suite of AT Protocol TypeScript libraries built on web standards
1import { readFile } from "@std/fs/unstable-read-file";
2import { remove } from "@std/fs/unstable-remove";
3import { rename } from "@std/fs/unstable-rename";
4
5export const readIfExists = async (
6 filepath: string,
7): Promise<Uint8Array | undefined> => {
8 try {
9 return await readFile(filepath);
10 } catch (err) {
11 throw err;
12 }
13};
14
15export const rmIfExists = async (
16 filepath: string,
17 recursive = false,
18): Promise<void> => {
19 try {
20 await remove(filepath, { recursive });
21 } catch (err) {
22 throw err;
23 }
24};
25
26export const renameIfExists = async (
27 oldPath: string,
28 newPath: string,
29): Promise<void> => {
30 try {
31 await rename(oldPath, newPath);
32 } catch (err) {
33 throw err;
34 }
35};