Skip to content

Commit 24fc929

Browse files
Format; Add FFI for access, copyFile, mkdtemp (#73)
* Format via purs-tidy * Add FFI for access, copyFile, mkdtemp * Format code a bit more * Move FileFlags to constants; re-export to prevent breakage * Add perms for common modes * Add docs to CopyMode constants * Add access and copyfile tests * Tweak readable file's perms before test * Fix file path * Print error * Tweak access again * Create temp dir before using it * Use local dir to avoid access errors * Refactor copyFile test to remove unlessM * Add changelog entry
1 parent a9da8b9 commit 24fc929

15 files changed

+729
-553
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Bugfixes:
1212

1313
Other improvements:
1414

15+
## [v8.2.0](https://github.com/purescript-node/purescript-node-fs/releases/tag/v8.2.0) - 2023-03-23
16+
17+
New features:
18+
- Add FFI for `access`, `copyFile` and `mkdtemp` (#73 by @JordanMartinez)
19+
1520
## [v8.1.1](https://github.com/purescript-node/purescript-node-fs/releases/tag/v8.1.1) - 2022-10-24
1621

1722
Other improvements:

src/Node/FS.purs

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,20 @@
11
module Node.FS
22
( FileDescriptor(..)
3-
, FileFlags(..)
43
, FileMode(..)
54
, SymlinkType(..)
65
, symlinkTypeToNode
76
, BufferLength(..)
87
, BufferOffset(..)
98
, ByteCount(..)
109
, FilePosition(..)
11-
, fileFlagsToNode
10+
, module Exports
1211
) where
1312

1413
import Prelude
1514

16-
foreign import data FileDescriptor :: Type
17-
18-
data FileFlags = R | R_PLUS | RS | RS_PLUS
19-
| W | WX | W_PLUS | WX_PLUS
20-
| A | AX | A_PLUS | AX_PLUS
21-
22-
instance showFileFlags :: Show FileFlags where
23-
show R = "R"
24-
show R_PLUS = "R_PLUS"
25-
show RS = "RS"
26-
show RS_PLUS = "RS_PLUS"
27-
show W = "W"
28-
show WX = "WX"
29-
show W_PLUS = "W_PLUS"
30-
show WX_PLUS = "WX_PLUS"
31-
show A = "A"
32-
show AX = "AX"
33-
show A_PLUS = "A_PLUS"
34-
show AX_PLUS = "AX_PLUS"
15+
import Node.FS.Constants (FileFlags(..), fileFlagsToNode) as Exports
3516

36-
instance eqFileFlags :: Eq FileFlags where
37-
eq x y = show x == show y
38-
39-
-- | Convert a `FileFlags` to a `String` in the format expected by the Node.js
40-
-- | filesystem API.
41-
fileFlagsToNode :: FileFlags -> String
42-
fileFlagsToNode ff = case ff of
43-
R -> "r"
44-
R_PLUS -> "r+"
45-
RS -> "rs"
46-
RS_PLUS -> "rs+"
47-
W -> "w"
48-
WX -> "wx"
49-
W_PLUS -> "w+"
50-
WX_PLUS -> "wx+"
51-
A -> "a"
52-
AX -> "ax"
53-
A_PLUS -> "a+"
54-
AX_PLUS -> "ax+"
17+
foreign import data FileDescriptor :: Type
5518

5619
type FileMode = Int
5720
type FilePosition = Int
@@ -71,12 +34,12 @@ symlinkTypeToNode ty = case ty of
7134
JunctionLink -> "junction"
7235

7336
instance showSymlinkType :: Show SymlinkType where
74-
show FileLink = "FileLink"
75-
show DirLink = "DirLink"
37+
show FileLink = "FileLink"
38+
show DirLink = "DirLink"
7639
show JunctionLink = "JunctionLink"
7740

7841
instance eqSymlinkType :: Eq SymlinkType where
79-
eq FileLink FileLink = true
80-
eq DirLink DirLink = true
42+
eq FileLink FileLink = true
43+
eq DirLink DirLink = true
8144
eq JunctionLink JunctionLink = true
8245
eq _ _ = false

src/Node/FS/Async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export {
2+
access as accessImpl,
3+
copyFile as copyFileImpl,
4+
mkdtemp as mkdtempImpl,
25
rename as renameImpl,
36
truncate as truncateImpl,
47
chown as chownImpl,
@@ -22,4 +25,4 @@ export {
2225
read as readImpl,
2326
write as writeImpl,
2427
close as closeImpl
25-
} from "fs";
28+
} from "node:fs";

0 commit comments

Comments
 (0)