Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 5ed121e

Browse files
Wrap new FFI: access, copyFile, mkdtemp (#40)
* Run purs-tidy formatter * Wrap access, copyFile, mkdtemp in Aff * Add changelog entry
1 parent ac9b6fd commit 5ed121e

File tree

3 files changed

+98
-55
lines changed

3 files changed

+98
-55
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Bugfixes:
1212

1313
Other improvements:
1414

15+
## [v9.2.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v9.2.0) - 2023-03-24
16+
17+
New features:
18+
19+
- Added `access`, `copyFile`, and `mkdtemp` (#40 by @JordanMartinez)
20+
1521
## [v9.1.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v9.1.0) - 2022-06-10
1622

1723
New features:

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"dependencies": {
3030
"purescript-aff": "^7.0.0",
3131
"purescript-either": "^6.0.0",
32-
"purescript-node-fs": "^8.1.0",
32+
"purescript-node-fs": "^8.2.0",
3333
"purescript-node-path": "^5.0.0"
3434
},
3535
"devDependencies": {

src/Node/FS/Aff.purs

+91-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
module Node.FS.Aff
2-
( rename
2+
( access
3+
, access'
4+
, copyFile
5+
, copyFile'
6+
, mkdtemp
7+
, mkdtemp'
8+
, rename
39
, truncate
410
, chown
511
, chmod
@@ -35,53 +41,82 @@ module Node.FS.Aff
3541
import Prelude
3642

3743
import Data.DateTime (DateTime)
44+
import Data.Either (Either(..))
3845
import Data.Maybe (Maybe)
3946
import Effect (Effect)
40-
import Effect.Aff (Aff, makeAff, nonCanceler)
47+
import Effect.Aff (Aff, Error, makeAff, nonCanceler)
4148
import Node.Buffer (Buffer)
4249
import Node.Encoding (Encoding)
4350
import Node.FS as F
4451
import Node.FS.Async as A
52+
import Node.FS.Constants (AccessMode, CopyMode)
4553
import Node.FS.Perms (Perms)
4654
import Node.FS.Stats (Stats)
4755
import Node.Path (FilePath)
4856

49-
toAff :: forall a.
50-
(A.Callback a -> Effect Unit) ->
51-
Aff a
57+
toAff
58+
:: forall a
59+
. (A.Callback a -> Effect Unit)
60+
-> Aff a
5261
toAff p = makeAff \k -> p k $> nonCanceler
5362

54-
toAff1 :: forall a x.
55-
(x -> A.Callback a -> Effect Unit) ->
56-
x ->
57-
Aff a
58-
toAff1 f a = toAff (f a)
59-
60-
toAff2 :: forall a x y.
61-
(x -> y -> A.Callback a -> Effect Unit) ->
62-
x ->
63-
y ->
64-
Aff a
65-
toAff2 f a b = toAff (f a b)
66-
67-
toAff3 :: forall a x y z.
68-
(x -> y -> z -> A.Callback a -> Effect Unit) ->
69-
x ->
70-
y ->
71-
z ->
72-
Aff a
63+
toAff1
64+
:: forall a x
65+
. (x -> A.Callback a -> Effect Unit)
66+
-> x
67+
-> Aff a
68+
toAff1 f a = toAff (f a)
69+
70+
toAff2
71+
:: forall a x y
72+
. (x -> y -> A.Callback a -> Effect Unit)
73+
-> x
74+
-> y
75+
-> Aff a
76+
toAff2 f a b = toAff (f a b)
77+
78+
toAff3
79+
:: forall a x y z
80+
. (x -> y -> z -> A.Callback a -> Effect Unit)
81+
-> x
82+
-> y
83+
-> z
84+
-> Aff a
7385
toAff3 f a b c = toAff (f a b c)
7486

75-
toAff5 :: forall a w v x y z.
76-
(w -> v -> x -> y -> z -> A.Callback a -> Effect Unit) ->
77-
w ->
78-
v ->
79-
x ->
80-
y ->
81-
z ->
82-
Aff a
87+
toAff5
88+
:: forall a w v x y z
89+
. (w -> v -> x -> y -> z -> A.Callback a -> Effect Unit)
90+
-> w
91+
-> v
92+
-> x
93+
-> y
94+
-> z
95+
-> Aff a
8396
toAff5 f a b c d e = toAff (f a b c d e)
8497

98+
access :: String -> Aff (Maybe Error)
99+
access path = makeAff \k -> do
100+
A.access path (k <<< Right)
101+
pure nonCanceler
102+
103+
access' :: String -> AccessMode -> Aff (Maybe Error)
104+
access' path mode = makeAff \k -> do
105+
A.access' path mode (k <<< Right)
106+
pure nonCanceler
107+
108+
copyFile :: String -> String -> Aff Unit
109+
copyFile = toAff2 A.copyFile
110+
111+
copyFile' :: String -> String -> CopyMode -> Aff Unit
112+
copyFile' = toAff3 A.copyFile'
113+
114+
mkdtemp :: String -> Aff String
115+
mkdtemp = toAff1 A.mkdtemp
116+
117+
mkdtemp' :: String -> Encoding -> Aff String
118+
mkdtemp' = toAff2 A.mkdtemp'
119+
85120
-- |
86121
-- | Rename a file.
87122
-- |
@@ -121,10 +156,11 @@ link = toAff2 A.link
121156
-- |
122157
-- | Creates a symlink.
123158
-- |
124-
symlink :: FilePath
125-
-> FilePath
126-
-> F.SymlinkType
127-
-> Aff Unit
159+
symlink
160+
:: FilePath
161+
-> FilePath
162+
-> F.SymlinkType
163+
-> Aff Unit
128164
symlink = toAff3 A.symlink
129165

130166
-- |
@@ -164,7 +200,6 @@ rmdir = toAff1 A.rmdir
164200
rmdir' :: FilePath -> { maxRetries :: Int, retryDelay :: Int } -> Aff Unit
165201
rmdir' = toAff2 A.rmdir'
166202

167-
168203
-- |
169204
-- | Deletes a file or directory.
170205
-- |
@@ -237,23 +272,24 @@ appendFile = toAff2 A.appendFile
237272
appendTextFile :: Encoding -> FilePath -> String -> Aff Unit
238273
appendTextFile = toAff3 A.appendTextFile
239274

240-
241275
-- | Open a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback)
242276
-- | for details.
243-
fdOpen :: FilePath
244-
-> F.FileFlags
245-
-> Maybe F.FileMode
246-
-> Aff F.FileDescriptor
277+
fdOpen
278+
:: FilePath
279+
-> F.FileFlags
280+
-> Maybe F.FileMode
281+
-> Aff F.FileDescriptor
247282
fdOpen = toAff3 A.fdOpen
248283

249284
-- | Read from a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback)
250285
-- | for details.
251-
fdRead :: F.FileDescriptor
252-
-> Buffer
253-
-> F.BufferOffset
254-
-> F.BufferLength
255-
-> Maybe F.FilePosition
256-
-> Aff F.ByteCount
286+
fdRead
287+
:: F.FileDescriptor
288+
-> Buffer
289+
-> F.BufferOffset
290+
-> F.BufferLength
291+
-> Maybe F.FilePosition
292+
-> Aff F.ByteCount
257293
fdRead = toAff5 A.fdRead
258294

259295
-- | Convenience function to fill the whole buffer from the current
@@ -263,12 +299,13 @@ fdNext = toAff2 A.fdNext
263299

264300
-- | Write to a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback)
265301
-- | for details.
266-
fdWrite :: F.FileDescriptor
267-
-> Buffer
268-
-> F.BufferOffset
269-
-> F.BufferLength
270-
-> Maybe F.FilePosition
271-
-> Aff F.ByteCount
302+
fdWrite
303+
:: F.FileDescriptor
304+
-> Buffer
305+
-> F.BufferOffset
306+
-> F.BufferLength
307+
-> Maybe F.FilePosition
308+
-> Aff F.ByteCount
272309
fdWrite = toAff5 A.fdWrite
273310

274311
-- | Convenience function to append the whole buffer to the current

0 commit comments

Comments
 (0)