Skip to content

Format; Add FFI for access, copyFile, mkdtemp #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Bugfixes:

Other improvements:

## [v8.2.0](https://github.com/purescript-node/purescript-node-fs/releases/tag/v8.2.0) - 2023-03-23

New features:
- Add FFI for `access`, `copyFile` and `mkdtemp` (#73 by @JordanMartinez)

## [v8.1.1](https://github.com/purescript-node/purescript-node-fs/releases/tag/v8.1.1) - 2022-10-24

Other improvements:
Expand Down
51 changes: 7 additions & 44 deletions src/Node/FS.purs
Original file line number Diff line number Diff line change
@@ -1,57 +1,20 @@
module Node.FS
( FileDescriptor(..)
, FileFlags(..)
, FileMode(..)
, SymlinkType(..)
, symlinkTypeToNode
, BufferLength(..)
, BufferOffset(..)
, ByteCount(..)
, FilePosition(..)
, fileFlagsToNode
, module Exports
) where

import Prelude

foreign import data FileDescriptor :: Type

data FileFlags = R | R_PLUS | RS | RS_PLUS
| W | WX | W_PLUS | WX_PLUS
| A | AX | A_PLUS | AX_PLUS

instance showFileFlags :: Show FileFlags where
show R = "R"
show R_PLUS = "R_PLUS"
show RS = "RS"
show RS_PLUS = "RS_PLUS"
show W = "W"
show WX = "WX"
show W_PLUS = "W_PLUS"
show WX_PLUS = "WX_PLUS"
show A = "A"
show AX = "AX"
show A_PLUS = "A_PLUS"
show AX_PLUS = "AX_PLUS"
import Node.FS.Constants (FileFlags(..), fileFlagsToNode) as Exports

instance eqFileFlags :: Eq FileFlags where
eq x y = show x == show y

-- | Convert a `FileFlags` to a `String` in the format expected by the Node.js
-- | filesystem API.
fileFlagsToNode :: FileFlags -> String
fileFlagsToNode ff = case ff of
R -> "r"
R_PLUS -> "r+"
RS -> "rs"
RS_PLUS -> "rs+"
W -> "w"
WX -> "wx"
W_PLUS -> "w+"
WX_PLUS -> "wx+"
A -> "a"
AX -> "ax"
A_PLUS -> "a+"
AX_PLUS -> "ax+"
foreign import data FileDescriptor :: Type

type FileMode = Int
type FilePosition = Int
Expand All @@ -71,12 +34,12 @@ symlinkTypeToNode ty = case ty of
JunctionLink -> "junction"

instance showSymlinkType :: Show SymlinkType where
show FileLink = "FileLink"
show DirLink = "DirLink"
show FileLink = "FileLink"
show DirLink = "DirLink"
show JunctionLink = "JunctionLink"

instance eqSymlinkType :: Eq SymlinkType where
eq FileLink FileLink = true
eq DirLink DirLink = true
eq FileLink FileLink = true
eq DirLink DirLink = true
eq JunctionLink JunctionLink = true
eq _ _ = false
5 changes: 4 additions & 1 deletion src/Node/FS/Async.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export {
access as accessImpl,
copyFile as copyFileImpl,
mkdtemp as mkdtempImpl,
rename as renameImpl,
truncate as truncateImpl,
chown as chownImpl,
Expand All @@ -22,4 +25,4 @@ export {
read as readImpl,
write as writeImpl,
close as closeImpl
} from "fs";
} from "node:fs";
Loading