diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f35a54..b5463f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ Bugfixes: Other improvements: +## [v9.2.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v9.2.0) - 2023-03-24 + +New features: + +- Added `access`, `copyFile`, and `mkdtemp` (#40 by @JordanMartinez) + ## [v9.1.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v9.1.0) - 2022-06-10 New features: diff --git a/bower.json b/bower.json index 727564a..4ba77e6 100644 --- a/bower.json +++ b/bower.json @@ -29,7 +29,7 @@ "dependencies": { "purescript-aff": "^7.0.0", "purescript-either": "^6.0.0", - "purescript-node-fs": "^8.1.0", + "purescript-node-fs": "^8.2.0", "purescript-node-path": "^5.0.0" }, "devDependencies": { diff --git a/src/Node/FS/Aff.purs b/src/Node/FS/Aff.purs index 9b2fd79..140352f 100644 --- a/src/Node/FS/Aff.purs +++ b/src/Node/FS/Aff.purs @@ -1,5 +1,11 @@ module Node.FS.Aff - ( rename + ( access + , access' + , copyFile + , copyFile' + , mkdtemp + , mkdtemp' + , rename , truncate , chown , chmod @@ -35,53 +41,82 @@ module Node.FS.Aff import Prelude import Data.DateTime (DateTime) +import Data.Either (Either(..)) import Data.Maybe (Maybe) import Effect (Effect) -import Effect.Aff (Aff, makeAff, nonCanceler) +import Effect.Aff (Aff, Error, makeAff, nonCanceler) import Node.Buffer (Buffer) import Node.Encoding (Encoding) import Node.FS as F import Node.FS.Async as A +import Node.FS.Constants (AccessMode, CopyMode) import Node.FS.Perms (Perms) import Node.FS.Stats (Stats) import Node.Path (FilePath) -toAff :: forall a. - (A.Callback a -> Effect Unit) -> - Aff a +toAff + :: forall a + . (A.Callback a -> Effect Unit) + -> Aff a toAff p = makeAff \k -> p k $> nonCanceler -toAff1 :: forall a x. - (x -> A.Callback a -> Effect Unit) -> - x -> - Aff a -toAff1 f a = toAff (f a) - -toAff2 :: forall a x y. - (x -> y -> A.Callback a -> Effect Unit) -> - x -> - y -> - Aff a -toAff2 f a b = toAff (f a b) - -toAff3 :: forall a x y z. - (x -> y -> z -> A.Callback a -> Effect Unit) -> - x -> - y -> - z -> - Aff a +toAff1 + :: forall a x + . (x -> A.Callback a -> Effect Unit) + -> x + -> Aff a +toAff1 f a = toAff (f a) + +toAff2 + :: forall a x y + . (x -> y -> A.Callback a -> Effect Unit) + -> x + -> y + -> Aff a +toAff2 f a b = toAff (f a b) + +toAff3 + :: forall a x y z + . (x -> y -> z -> A.Callback a -> Effect Unit) + -> x + -> y + -> z + -> Aff a toAff3 f a b c = toAff (f a b c) -toAff5 :: forall a w v x y z. - (w -> v -> x -> y -> z -> A.Callback a -> Effect Unit) -> - w -> - v -> - x -> - y -> - z -> - Aff a +toAff5 + :: forall a w v x y z + . (w -> v -> x -> y -> z -> A.Callback a -> Effect Unit) + -> w + -> v + -> x + -> y + -> z + -> Aff a toAff5 f a b c d e = toAff (f a b c d e) +access :: String -> Aff (Maybe Error) +access path = makeAff \k -> do + A.access path (k <<< Right) + pure nonCanceler + +access' :: String -> AccessMode -> Aff (Maybe Error) +access' path mode = makeAff \k -> do + A.access' path mode (k <<< Right) + pure nonCanceler + +copyFile :: String -> String -> Aff Unit +copyFile = toAff2 A.copyFile + +copyFile' :: String -> String -> CopyMode -> Aff Unit +copyFile' = toAff3 A.copyFile' + +mkdtemp :: String -> Aff String +mkdtemp = toAff1 A.mkdtemp + +mkdtemp' :: String -> Encoding -> Aff String +mkdtemp' = toAff2 A.mkdtemp' + -- | -- | Rename a file. -- | @@ -121,10 +156,11 @@ link = toAff2 A.link -- | -- | Creates a symlink. -- | -symlink :: FilePath - -> FilePath - -> F.SymlinkType - -> Aff Unit +symlink + :: FilePath + -> FilePath + -> F.SymlinkType + -> Aff Unit symlink = toAff3 A.symlink -- | @@ -164,7 +200,6 @@ rmdir = toAff1 A.rmdir rmdir' :: FilePath -> { maxRetries :: Int, retryDelay :: Int } -> Aff Unit rmdir' = toAff2 A.rmdir' - -- | -- | Deletes a file or directory. -- | @@ -237,23 +272,24 @@ appendFile = toAff2 A.appendFile appendTextFile :: Encoding -> FilePath -> String -> Aff Unit appendTextFile = toAff3 A.appendTextFile - -- | Open a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback) -- | for details. -fdOpen :: FilePath - -> F.FileFlags - -> Maybe F.FileMode - -> Aff F.FileDescriptor +fdOpen + :: FilePath + -> F.FileFlags + -> Maybe F.FileMode + -> Aff F.FileDescriptor fdOpen = toAff3 A.fdOpen -- | Read from a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) -- | for details. -fdRead :: F.FileDescriptor - -> Buffer - -> F.BufferOffset - -> F.BufferLength - -> Maybe F.FilePosition - -> Aff F.ByteCount +fdRead + :: F.FileDescriptor + -> Buffer + -> F.BufferOffset + -> F.BufferLength + -> Maybe F.FilePosition + -> Aff F.ByteCount fdRead = toAff5 A.fdRead -- | Convenience function to fill the whole buffer from the current @@ -263,12 +299,13 @@ fdNext = toAff2 A.fdNext -- | Write to a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback) -- | for details. -fdWrite :: F.FileDescriptor - -> Buffer - -> F.BufferOffset - -> F.BufferLength - -> Maybe F.FilePosition - -> Aff F.ByteCount +fdWrite + :: F.FileDescriptor + -> Buffer + -> F.BufferOffset + -> F.BufferLength + -> Maybe F.FilePosition + -> Aff F.ByteCount fdWrite = toAff5 A.fdWrite -- | Convenience function to append the whole buffer to the current