Skip to content

Commit 257d0fa

Browse files
committed
Realpath
1 parent ee8a0fc commit 257d0fa

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040

4141
readlink :: forall eff. FilePath -> Callback eff FilePath -> Eff (fs :: FS | eff) Unit
4242

43+
realpath :: forall eff. FilePath -> Callback eff FilePath -> Eff (fs :: FS | eff) Unit
44+
45+
realpath' :: forall eff cache. FilePath -> { | cache } -> Callback eff FilePath -> Eff (fs :: FS | eff) Unit
46+
4347
rename :: forall eff. FilePath -> FilePath -> Callback eff Unit -> Eff (fs :: FS | eff) Unit
4448

4549
stat :: forall eff. FilePath -> Callback eff Stats -> Eff (fs :: FS | eff) Unit
@@ -107,6 +111,10 @@
107111

108112
readlink :: forall eff. FilePath -> Eff (err :: Exception Error, fs :: FS | eff) FilePath
109113

114+
realpath :: forall eff. FilePath -> Eff (err :: Exception Error, fs :: FS | eff) FilePath
115+
116+
realpath' :: forall eff cache. FilePath -> { | cache } -> Eff (err :: Exception Error, fs :: FS | eff) FilePath
117+
110118
rename :: forall eff. FilePath -> FilePath -> Eff (err :: Exception Error, fs :: FS | eff) Unit
111119

112120
stat :: forall eff. FilePath -> Eff (err :: Exception Error, fs :: FS | eff) Stats

src/Node/FS/Async.purs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Node.FS.Async
88
, link
99
, symlink
1010
, readlink
11+
, realpath
12+
, realpath'
1113
, readFile
1214
, readTextFile
1315
, writeFile
@@ -48,6 +50,7 @@ foreign import fs "var fs = require('fs');" ::
4850
, link :: Fn3 FilePath FilePath (JSCallback Unit) Unit
4951
, symlink :: Fn4 FilePath FilePath String (JSCallback Unit) Unit
5052
, readlink :: Fn2 FilePath (JSCallback FilePath) Unit
53+
, realpath :: forall cache. Fn3 FilePath { | cache } (JSCallback FilePath) Unit
5154
, readFile :: forall a opts. Fn3 FilePath { | opts } (JSCallback a) Unit
5255
, writeFile :: forall a opts. Fn4 FilePath a { | opts } (JSCallback Unit) Unit
5356
}
@@ -145,6 +148,28 @@ readlink :: forall eff. FilePath
145148
readlink path cb = return $ runFn2
146149
fs.readlink path (handleCallback cb)
147150

151+
-- |
152+
-- Find the canonicalized absolute location for a path.
153+
--
154+
realpath :: forall eff. FilePath
155+
-> Callback eff FilePath
156+
-> Eff (fs :: FS | eff) Unit
157+
158+
realpath path cb = return $ runFn3
159+
fs.realpath path {} (handleCallback cb)
160+
161+
-- |
162+
-- Find the canonicalized absolute location for a path using a cache object for
163+
-- already resolved paths.
164+
--
165+
realpath' :: forall eff cache. FilePath
166+
-> { | cache }
167+
-> Callback eff FilePath
168+
-> Eff (fs :: FS | eff) Unit
169+
170+
realpath' path cache cb = return $ runFn3
171+
fs.realpath path cache (handleCallback cb)
172+
148173
-- |
149174
-- Reads the entire contents of a file returning the result as a raw buffer.
150175
--

src/Node/FS/Sync.purs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Node.FS.Sync
77
, link
88
, symlink
99
, readlink
10+
, realpath
11+
, realpath'
1012
, readFile
1113
, readTextFile
1214
, writeFile
@@ -32,6 +34,7 @@ foreign import fs "var fs = require('fs');" ::
3234
, linkSync :: Fn2 FilePath FilePath Unit
3335
, symlinkSync :: Fn3 FilePath FilePath String Unit
3436
, readlinkSync :: Fn1 FilePath FilePath
37+
, realpathSync :: forall cache. Fn2 FilePath { | cache } FilePath
3538
, readFileSync :: forall a opts. Fn2 FilePath { | opts } a
3639
, writeFileSync :: forall a opts. Fn3 FilePath a { | opts } Unit
3740
}
@@ -121,6 +124,26 @@ readlink :: forall eff. FilePath
121124
readlink path = mkEff $ \_ -> runFn1
122125
fs.readlinkSync path
123126

127+
-- |
128+
-- Find the canonicalized absolute location for a path.
129+
--
130+
realpath :: forall eff. FilePath
131+
-> Eff (fs :: FS, err :: Exception Error | eff) FilePath
132+
133+
realpath path = mkEff $ \_ -> runFn2
134+
fs.realpathSync path {}
135+
136+
-- |
137+
-- Find the canonicalized absolute location for a path using a cache object for
138+
-- already resolved paths.
139+
--
140+
realpath' :: forall eff cache. FilePath
141+
-> { | cache }
142+
-> Eff (fs :: FS, err :: Exception Error | eff) FilePath
143+
144+
realpath' path cache = mkEff $ \_ -> runFn2
145+
fs.realpathSync path cache
146+
124147
-- |
125148
-- Reads the entire contents of a file returning the result as a raw buffer.
126149
--

0 commit comments

Comments
 (0)