Skip to content

Commit 97845cb

Browse files
committed
Readdir
1 parent 2666aa6 commit 97845cb

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
readTextFile :: forall eff. Encoding -> FilePath -> Callback eff String -> Eff (fs :: FS | eff) Unit
4444

45+
readdir :: forall eff. FilePath -> Callback eff [FilePath] -> Eff (fs :: FS | eff) Unit
46+
4547
readlink :: forall eff. FilePath -> Callback eff FilePath -> Eff (fs :: FS | eff) Unit
4648

4749
realpath :: forall eff. FilePath -> Callback eff FilePath -> Eff (fs :: FS | eff) Unit
@@ -121,6 +123,8 @@
121123

122124
readTextFile :: forall eff. Encoding -> FilePath -> Eff (err :: Exception Error, fs :: FS | eff) String
123125

126+
readdir :: forall eff. FilePath -> Eff (err :: Exception Error, fs :: FS | eff) [FilePath]
127+
124128
readlink :: forall eff. FilePath -> Eff (err :: Exception Error, fs :: FS | eff) FilePath
125129

126130
realpath :: forall eff. FilePath -> Eff (err :: Exception Error, fs :: FS | eff) FilePath

src/Node/FS/Async.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Node.FS.Async
1414
, rmdir
1515
, mkdir
1616
, mkdir'
17+
, readdir
1718
, readFile
1819
, readTextFile
1920
, writeFile
@@ -58,6 +59,7 @@ foreign import fs "var fs = require('fs');" ::
5859
, unlink :: Fn2 FilePath (JSCallback Unit) Unit
5960
, rmdir :: Fn2 FilePath (JSCallback Unit) Unit
6061
, mkdir :: Fn3 FilePath Number (JSCallback Unit) Unit
62+
, readdir :: Fn2 FilePath (JSCallback [FilePath]) Unit
6163
, readFile :: forall a opts. Fn3 FilePath { | opts } (JSCallback a) Unit
6264
, writeFile :: forall a opts. Fn4 FilePath a { | opts } (JSCallback Unit) Unit
6365
}
@@ -217,6 +219,16 @@ mkdir' :: forall eff. FilePath
217219
mkdir' file mode cb = return $ runFn3
218220
fs.mkdir file mode (handleCallback cb)
219221

222+
-- |
223+
-- Reads the contents of a directory.
224+
--
225+
readdir :: forall eff. FilePath
226+
-> Callback eff [FilePath]
227+
-> Eff (fs :: FS | eff) Unit
228+
229+
readdir file cb = return $ runFn2
230+
fs.readdir file (handleCallback cb)
231+
220232
-- |
221233
-- Reads the entire contents of a file returning the result as a raw buffer.
222234
--

src/Node/FS/Sync.purs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Node.FS.Sync
1313
, rmdir
1414
, mkdir
1515
, mkdir'
16+
, readdir
1617
, readFile
1718
, readTextFile
1819
, writeFile
@@ -42,6 +43,7 @@ foreign import fs "var fs = require('fs');" ::
4243
, unlinkSync :: Fn1 FilePath Unit
4344
, rmdirSync :: Fn1 FilePath Unit
4445
, mkdirSync :: Fn2 FilePath Number Unit
46+
, readdirSync :: Fn1 FilePath [FilePath]
4547
, readFileSync :: forall a opts. Fn2 FilePath { | opts } a
4648
, writeFileSync :: forall a opts. Fn3 FilePath a { | opts } Unit
4749
}
@@ -187,6 +189,15 @@ mkdir' :: forall eff. FilePath
187189
mkdir' file mode = mkEff $ \_ -> runFn2
188190
fs.mkdirSync file mode
189191

192+
-- |
193+
-- Reads the contents of a directory.
194+
--
195+
readdir :: forall eff. FilePath
196+
-> Eff (fs :: FS, err :: Exception Error | eff) [FilePath]
197+
198+
readdir file = mkEff $ \_ -> runFn1
199+
fs.readdirSync file
200+
190201
-- |
191202
-- Reads the entire contents of a file returning the result as a raw buffer.
192203
--

0 commit comments

Comments
 (0)