Skip to content

Commit 8acc0eb

Browse files
committed
AppendFile
1 parent 1d329b8 commit 8acc0eb

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

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

2929
### Values
3030

31+
appendFile :: forall eff. FilePath -> Buffer -> Callback eff Unit -> Eff (fs :: FS | eff) Unit
32+
33+
appendTextFile :: forall eff. Encoding -> FilePath -> String -> Callback eff Unit -> Eff (fs :: FS | eff) Unit
34+
3135
chmod :: forall eff. FilePath -> Number -> Callback eff Unit -> Eff (fs :: FS | eff) Unit
3236

3337
chown :: forall eff. FilePath -> Number -> Number -> Callback eff Unit -> Eff (fs :: FS | eff) Unit
@@ -111,6 +115,10 @@
111115

112116
### Values
113117

118+
appendFile :: forall eff. FilePath -> Buffer -> Eff (err :: Exception Error, fs :: FS | eff) Unit
119+
120+
appendTextFile :: forall eff. Encoding -> FilePath -> String -> Eff (err :: Exception Error, fs :: FS | eff) Unit
121+
114122
chmod :: forall eff. FilePath -> Number -> Eff (err :: Exception Error, fs :: FS | eff) Unit
115123

116124
chown :: forall eff. FilePath -> Number -> Number -> Eff (err :: Exception Error, fs :: FS | eff) Unit

src/Node/FS/Async.purs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module Node.FS.Async
2020
, readTextFile
2121
, writeFile
2222
, writeTextFile
23+
, appendFile
24+
, appendTextFile
2325
) where
2426

2527
import Control.Monad.Eff
@@ -65,6 +67,7 @@ foreign import fs "var fs = require('fs');" ::
6567
, utimes :: Fn4 FilePath Number Number (JSCallback Unit) Unit
6668
, readFile :: forall a opts. Fn3 FilePath { | opts } (JSCallback a) Unit
6769
, writeFile :: forall a opts. Fn4 FilePath a { | opts } (JSCallback Unit) Unit
70+
, appendFile :: forall a opts. Fn4 FilePath a { | opts } (JSCallback Unit) Unit
6871
}
6972

7073
-- |
@@ -290,3 +293,26 @@ writeTextFile :: forall eff. Encoding
290293

291294
writeTextFile encoding file buff cb = return $ runFn4
292295
fs.writeFile file buff { encoding: show encoding } (handleCallback cb)
296+
297+
-- |
298+
-- Appends the contents of a buffer to a file.
299+
--
300+
appendFile :: forall eff. FilePath
301+
-> Buffer
302+
-> Callback eff Unit
303+
-> Eff (fs :: FS | eff) Unit
304+
305+
appendFile file buff cb = return $ runFn4
306+
fs.appendFile file buff {} (handleCallback cb)
307+
308+
-- |
309+
-- Appends text to a file using the specified encoding.
310+
--
311+
appendTextFile :: forall eff. Encoding
312+
-> FilePath
313+
-> String
314+
-> Callback eff Unit
315+
-> Eff (fs :: FS | eff) Unit
316+
317+
appendTextFile encoding file buff cb = return $ runFn4
318+
fs.appendFile file buff { encoding: show encoding } (handleCallback cb)

src/Node/FS/Sync.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module Node.FS.Sync
1919
, readTextFile
2020
, writeFile
2121
, writeTextFile
22+
, appendFile
23+
, appendTextFile
2224
) where
2325

2426
import Control.Monad.Eff
@@ -49,6 +51,7 @@ foreign import fs "var fs = require('fs');" ::
4951
, utimesSync :: Fn3 FilePath Number Number Unit
5052
, readFileSync :: forall a opts. Fn2 FilePath { | opts } a
5153
, writeFileSync :: forall a opts. Fn3 FilePath a { | opts } Unit
54+
, appendFileSync :: forall a opts. Fn3 FilePath a { | opts } Unit
5255
}
5356

5457
foreign import mkEff
@@ -253,3 +256,24 @@ writeTextFile :: forall eff. Encoding
253256

254257
writeTextFile encoding file buff = mkEff $ \_ -> runFn3
255258
fs.writeFileSync file buff { encoding: show encoding }
259+
260+
-- |
261+
-- Appends the contents of a buffer to a file.
262+
--
263+
appendFile :: forall eff. FilePath
264+
-> Buffer
265+
-> Eff (fs :: FS, err :: Exception Error | eff) Unit
266+
267+
appendFile file buff = mkEff $ \_ -> runFn3
268+
fs.appendFileSync file buff {}
269+
270+
-- |
271+
-- Appends text to a file using the specified encoding.
272+
--
273+
appendTextFile :: forall eff. Encoding
274+
-> FilePath
275+
-> String
276+
-> Eff (fs :: FS, err :: Exception Error | eff) Unit
277+
278+
appendTextFile encoding file buff = mkEff $ \_ -> runFn3
279+
fs.appendFileSync file buff { encoding: show encoding }

0 commit comments

Comments
 (0)