-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
273 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ dump.rdb | |
pnpm-* | ||
coverage | ||
.vscode/pinned-files.json | ||
.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
export const fsw = { | ||
async writeFile(filePath: string, data: string): Promise<void> { | ||
try { | ||
await fs.promises.writeFile(filePath, data, 'utf-8'); | ||
} catch (error) { | ||
console.error(`Error writing file ${filePath}:`, error); | ||
throw error; | ||
} | ||
}, | ||
|
||
async readFile(filePath: string): Promise<string> { | ||
try { | ||
return await fs.promises.readFile(filePath, 'utf-8'); | ||
} catch (error) { | ||
console.error(`Error reading file ${filePath}:`, error); | ||
throw error; | ||
} | ||
}, | ||
|
||
async unlink(filePath: string): Promise<void> { | ||
try { | ||
await fs.promises.unlink(filePath); | ||
} catch (error) { | ||
console.error(`Error deleting file ${filePath}:`, error); | ||
throw error; | ||
} | ||
}, | ||
|
||
async exists(filePath: string): Promise<boolean> { | ||
try { | ||
await fs.promises.access(filePath, fs.constants.F_OK); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}, | ||
|
||
async mkdir(dirPath: string): Promise<void> { | ||
try { | ||
await fs.promises.mkdir(dirPath, { recursive: true }); | ||
} catch (error) { | ||
console.error(`Error creating directory ${dirPath}:`, error); | ||
throw error; | ||
} | ||
}, | ||
|
||
async copyFile(src: string, dest: string): Promise<void> { | ||
try { | ||
await fs.promises.copyFile(src, dest); | ||
} catch (error) { | ||
console.error(`Error copying file from ${src} to ${dest}:`, error); | ||
throw error; | ||
} | ||
} | ||
}; |
Oops, something went wrong.