aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/build/packages/simplifile/src/simplifile_js.mjs
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-10-09 11:35:09 -0400
committerH.J <thechairman@thechairman.info>2024-10-09 11:35:09 -0400
commit6156a9ef7be4012063a042aafb4e9b0d7eadde8e (patch)
tree5d990ded3baba51ca3934b51994285f7d5915c34 /aoc2023/build/packages/simplifile/src/simplifile_js.mjs
parentef2ad0ee020b6754c230ae08f5979948b8db1350 (diff)
downloadgleam_aoc-6156a9ef7be4012063a042aafb4e9b0d7eadde8e.tar.gz
gleam_aoc-6156a9ef7be4012063a042aafb4e9b0d7eadde8e.zip
cleanup
Diffstat (limited to 'aoc2023/build/packages/simplifile/src/simplifile_js.mjs')
-rw-r--r--aoc2023/build/packages/simplifile/src/simplifile_js.mjs102
1 files changed, 0 insertions, 102 deletions
diff --git a/aoc2023/build/packages/simplifile/src/simplifile_js.mjs b/aoc2023/build/packages/simplifile/src/simplifile_js.mjs
deleted file mode 100644
index faf4109..0000000
--- a/aoc2023/build/packages/simplifile/src/simplifile_js.mjs
+++ /dev/null
@@ -1,102 +0,0 @@
-import fs from "node:fs"
-import path from "node:path"
-import { BitArray, Ok, Error as GError, toList} from "./gleam.mjs";
-
-export function readBits(filepath) {
- try {
- const contents = fs.readFileSync(path.normalize(filepath))
- return new Ok(new BitArray(new Uint8Array(contents)))
- } catch(e) {
- return new GError(stringifyError(e))
- }
-}
-
-export function writeBits(contents, filepath) {
- try {
- fs.writeFileSync(path.normalize(filepath), contents.buffer)
- return new Ok(undefined)
- } catch (e) {
- return new GError(stringifyError(e))
- }
-}
-
-export function appendBits(contents, filepath) {
- try {
- fs.appendFileSync(path.normalize(filepath), contents.buffer)
- return new Ok(undefined)
- } catch (e) {
- return new GError(stringifyError(e))
- }
-}
-
-function stringifyError(e) {
- return e.code
-}
-
-export function isFile(filepath) {
- let fp = path.normalize(filepath)
- return fs.existsSync(fp) && fs.lstatSync(fp).isFile();
-}
-
-export function isDirectory(filepath) {
- let fp = path.normalize(filepath)
- return fs.existsSync(fp) && fs.lstatSync(fp).isDirectory();
-}
-
-export function makeDirectory(filepath) {
- try {
- fs.mkdirSync(path.normalize(filepath))
- return new Ok(undefined)
- } catch (e) {
- return new GError(stringifyError(e))
- }
-}
-
-export function createDirAll(filepath) {
- try {
- fs.mkdirSync(filepath, { recursive: true })
- return new Ok(undefined)
- } catch (e) {
- return new GError(stringifyError(e))
- }
-}
-
-export function deleteFileOrDirRecursive(fileOrDirPath) {
- try {
- if (isDirectory(fileOrDirPath)) {
- fs.rmSync(path.normalize(fileOrDirPath), { recursive: true })
- } else {
- fs.unlinkSync(path.normalize(fileOrDirPath))
- }
- return new Ok(undefined)
- } catch (e) {
- return new GError(stringifyError(e))
- }
-}
-
-export function listContents(filepath) {
- try {
- const stuff = toList(fs.readdirSync(path.normalize(filepath)))
- return new Ok(stuff)
- } catch(e) {
- return new GError(stringifyError(e))
- }
-}
-
-export function copyFile(srcpath, destpath) {
- try {
- fs.copyFileSync(path.normalize(srcpath), path.normalize(destpath))
- return new Ok(undefined)
- } catch (e) {
- return new GError(stringifyError(e))
- }
-}
-
-export function renameFile(srcpath, destpath) {
- try {
- fs.renameSync(path.normalize(srcpath), path.normalize(destpath))
- return new Ok(undefined)
- } catch (e) {
- return new GError(stringifyError(e))
- }
-} \ No newline at end of file