├── .gitignore ├── package.json ├── README.md ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── ci.yml ├── test └── Main.purs ├── bower.json ├── CHANGELOG.md └── src └── Node └── FS └── Aff.purs /.gitignore: -------------------------------------------------------------------------------- 1 | /.* 2 | !/.gitignore 3 | !/.github/ 4 | /bower_components/ 5 | /node_modules/ 6 | /tmp/ 7 | /output/ 8 | package-lock.json 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "clean": "rimraf output && rimraf .pulp-cache", 5 | "build": "pulp build -- --censor-lib --strict", 6 | "test": "pulp test" 7 | }, 8 | "devDependencies": { 9 | "pulp": "16.0.0-0", 10 | "purescript-psa": "^0.8.2", 11 | "rimraf": "^3.0.2" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED 2 | 3 | `purescript-node-fs-aff` is deprecated. Functions and values from this library were merged as-is into the [`purescript-node-fs`](https://github.com/purescript/purescript-node-fs) library. 4 | 5 | The [original releases up to v9.2.0](https://github.com/purescript-deprecated/purescript-node-fs-aff/releases) of this library are still available and will work with compiler versions prior to PureScript v0.16.x. 6 | 7 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Description of the change** 2 | 3 | Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR. 4 | 5 | --- 6 | 7 | **Checklist:** 8 | 9 | - [ ] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)") 10 | - [ ] Linked any existing issues or proposals that this pull request should close 11 | - [ ] Updated or added relevant documentation 12 | - [ ] Added a test for the contribution (if applicable) 13 | -------------------------------------------------------------------------------- /test/Main.purs: -------------------------------------------------------------------------------- 1 | module Test.Main where 2 | 3 | import Prelude 4 | 5 | import Data.Array (filterA) 6 | import Data.Maybe (maybe) 7 | import Data.String.CodeUnits (charAt, singleton) 8 | import Effect (Effect) 9 | import Effect.Aff (launchAff_) 10 | import Effect.Class (liftEffect) 11 | import Effect.Console (log) 12 | import Node.FS.Aff (stat, readdir) 13 | import Node.FS.Stats (isDirectory) 14 | 15 | main :: Effect Unit 16 | main = launchAff_ do 17 | files <- readdir "." 18 | files' <- flip filterA files \file -> do 19 | stat <- stat file 20 | pure $ isDirectory stat 21 | && (maybe false (singleton >>> (_ /= ".")) $ charAt 0 file) 22 | liftEffect $ log $ show files' 23 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | branches: [master] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - uses: purescript-contrib/setup-purescript@main 16 | with: 17 | purescript: "unstable" 18 | 19 | - uses: actions/setup-node@v2 20 | with: 21 | node-version: "14" 22 | 23 | - name: Install dependencies 24 | run: | 25 | npm install -g bower 26 | npm install 27 | bower install --production 28 | 29 | - name: Build source 30 | run: npm run-script build 31 | 32 | - name: Run tests 33 | run: | 34 | bower install 35 | npm run-script test --if-present 36 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purescript-node-fs-aff", 3 | "authors": [ 4 | "Felix Schlitter " 5 | ], 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/purescript-deprecated/purescript-node-fs-aff.git" 9 | }, 10 | "description": "Aff wrappers for purescript-node-fs", 11 | "keywords": [ 12 | "purescript", 13 | "node", 14 | "pursuit-deprecated" 15 | ], 16 | "license": "MIT", 17 | "homepage": "https://github.com/purescript-deprecated/purescript-node-fs-aff", 18 | "ignore": [ 19 | "**/.*", 20 | "node_modules", 21 | "bower_components", 22 | "test", 23 | "tests", 24 | "output", 25 | "tmp", 26 | "bower.json", 27 | "package.json", 28 | "example" 29 | ], 30 | "dependencies": { 31 | "purescript-aff": "^7.0.0", 32 | "purescript-either": "^6.0.0", 33 | "purescript-node-fs": "^8.2.0", 34 | "purescript-node-path": "^5.0.0" 35 | }, 36 | "devDependencies": { 37 | "purescript-console": "^6.0.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 4 | 5 | ## [Unreleased] 6 | 7 | Breaking changes: 8 | 9 | New features: 10 | 11 | Bugfixes: 12 | 13 | Other improvements: 14 | 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 | 21 | ## [v9.1.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v9.1.0) - 2022-06-10 22 | 23 | New features: 24 | 25 | - Update rmdir' to take options arg (#39 by @wclr) 26 | - Added rm and rm' versions with and without options arg (#39 by @wclr) 27 | 28 | ## [v9.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v9.0.0) - 2022-04-29 29 | 30 | Breaking changes: 31 | - Remove `exists` since the underlying `Async.exists` from `purescript-node-fs` has been removed (#36 by @sigma-andex) 32 | - Update project and deps to PureScript v0.15.0 (#33 by @JordanMartinez, @thomashoneyman, @sigma-andex) 33 | - Update `mkdir'` to take options arg (#34 by @JordanMartinez) 34 | 35 | ## [v8.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v8.0.0) - 2022-04-27 36 | 37 | Due to implementing a breaking change incorrectly, use v10.0.0 instead. 38 | 39 | ## [v7.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v7.0.0) - 2021-02-26 40 | 41 | Breaking changes: 42 | - Added support for PureScript 0.14 and dropped support for all previous versions (#27) 43 | 44 | Other improvements: 45 | - Migrated CI to GitHub Actions (#25) 46 | - Added a changelog and pull request template (#28) 47 | 48 | ## [v6.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v6.0.0) - 2018-05-29 49 | 50 | - Updates for 0.12 51 | 52 | ## [v5.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v5.0.0) - 2017-10-03 53 | 54 | - Updated for Aff v4 55 | 56 | ## [v4.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v4.0.0) - 2017-04-05 57 | 58 | Updates for 0.11 compiler 59 | 60 | ## [v3.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v3.0.0) - 2016-10-21 61 | 62 | - Updated dependencies 63 | 64 | ## [v2.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v2.0.0) - 2016-07-31 65 | 66 | - Updated dependencies 67 | 68 | ## [v1.0.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v1.0.0) - 2016-06-12 69 | 70 | - Updates for 1.0 core libraries and 0.9.1 compiler. 71 | 72 | ## [v0.5.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v0.5.0) - 2016-03-15 73 | 74 | - Updated Aff dependency range 75 | 76 | ## [v0.4.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v0.4.0) - 2016-03-15 77 | 78 | - Updated Aff dependency range 79 | 80 | ## [v0.1.0](https://github.com/purescript-node/purescript-node-fs-aff/releases/tag/v0.1.0) - 2015-08-11 81 | 82 | - Initial tagged release. 83 | -------------------------------------------------------------------------------- /src/Node/FS/Aff.purs: -------------------------------------------------------------------------------- 1 | module Node.FS.Aff 2 | ( access 3 | , access' 4 | , copyFile 5 | , copyFile' 6 | , mkdtemp 7 | , mkdtemp' 8 | , rename 9 | , truncate 10 | , chown 11 | , chmod 12 | , stat 13 | , link 14 | , symlink 15 | , readlink 16 | , realpath 17 | , realpath' 18 | , unlink 19 | , rmdir 20 | , rmdir' 21 | , rm 22 | , rm' 23 | , mkdir 24 | , mkdir' 25 | , readdir 26 | , utimes 27 | , readFile 28 | , readTextFile 29 | , writeFile 30 | , writeTextFile 31 | , appendFile 32 | , appendTextFile 33 | , fdOpen 34 | , fdRead 35 | , fdNext 36 | , fdWrite 37 | , fdAppend 38 | , fdClose 39 | ) where 40 | 41 | import Prelude 42 | 43 | import Data.DateTime (DateTime) 44 | import Data.Either (Either(..)) 45 | import Data.Maybe (Maybe) 46 | import Effect (Effect) 47 | import Effect.Aff (Aff, Error, makeAff, nonCanceler) 48 | import Node.Buffer (Buffer) 49 | import Node.Encoding (Encoding) 50 | import Node.FS as F 51 | import Node.FS.Async as A 52 | import Node.FS.Constants (AccessMode, CopyMode) 53 | import Node.FS.Perms (Perms) 54 | import Node.FS.Stats (Stats) 55 | import Node.Path (FilePath) 56 | 57 | toAff 58 | :: forall a 59 | . (A.Callback a -> Effect Unit) 60 | -> Aff a 61 | toAff p = makeAff \k -> p k $> nonCanceler 62 | 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 85 | toAff3 f a b c = toAff (f a b c) 86 | 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 96 | toAff5 f a b c d e = toAff (f a b c d e) 97 | 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 | 120 | -- | 121 | -- | Rename a file. 122 | -- | 123 | rename :: FilePath -> FilePath -> Aff Unit 124 | rename = toAff2 A.rename 125 | 126 | -- | 127 | -- | Truncates a file to the specified length. 128 | -- | 129 | truncate :: FilePath -> Int -> Aff Unit 130 | truncate = toAff2 A.truncate 131 | 132 | -- | 133 | -- | Changes the ownership of a file. 134 | -- | 135 | chown :: FilePath -> Int -> Int -> Aff Unit 136 | chown = toAff3 A.chown 137 | 138 | -- | 139 | -- | Changes the permissions of a file. 140 | -- | 141 | chmod :: FilePath -> Perms -> Aff Unit 142 | chmod = toAff2 A.chmod 143 | 144 | -- | 145 | -- | Gets file statistics. 146 | -- | 147 | stat :: FilePath -> Aff Stats 148 | stat = toAff1 A.stat 149 | 150 | -- | 151 | -- | Creates a link to an existing file. 152 | -- | 153 | link :: FilePath -> FilePath -> Aff Unit 154 | link = toAff2 A.link 155 | 156 | -- | 157 | -- | Creates a symlink. 158 | -- | 159 | symlink 160 | :: FilePath 161 | -> FilePath 162 | -> F.SymlinkType 163 | -> Aff Unit 164 | symlink = toAff3 A.symlink 165 | 166 | -- | 167 | -- | Reads the value of a symlink. 168 | -- | 169 | readlink :: FilePath -> Aff FilePath 170 | readlink = toAff1 A.readlink 171 | 172 | -- | 173 | -- | Find the canonicalized absolute location for a path. 174 | -- | 175 | realpath :: FilePath -> Aff FilePath 176 | realpath = toAff1 A.realpath 177 | 178 | -- | 179 | -- | Find the canonicalized absolute location for a path using a cache object 180 | -- | for already resolved paths. 181 | -- | 182 | realpath' :: forall cache. FilePath -> { | cache } -> Aff FilePath 183 | realpath' = toAff2 A.realpath' 184 | 185 | -- | 186 | -- | Deletes a file. 187 | -- | 188 | unlink :: FilePath -> Aff Unit 189 | unlink = toAff1 A.unlink 190 | 191 | -- | 192 | -- | Deletes a directory. 193 | -- | 194 | rmdir :: FilePath -> Aff Unit 195 | rmdir = toAff1 A.rmdir 196 | 197 | -- | 198 | -- | Deletes a directory with options. 199 | -- | 200 | rmdir' :: FilePath -> { maxRetries :: Int, retryDelay :: Int } -> Aff Unit 201 | rmdir' = toAff2 A.rmdir' 202 | 203 | -- | 204 | -- | Deletes a file or directory. 205 | -- | 206 | rm :: FilePath -> Aff Unit 207 | rm = toAff1 A.rmdir 208 | 209 | -- | 210 | -- | Deletes a file or directory with options. 211 | -- | 212 | rm' :: FilePath -> { force :: Boolean, maxRetries :: Int, recursive :: Boolean, retryDelay :: Int } -> Aff Unit 213 | rm' = toAff2 A.rm' 214 | 215 | -- | 216 | -- | Makes a new directory. 217 | -- | 218 | mkdir :: FilePath -> Aff Unit 219 | mkdir = toAff1 A.mkdir 220 | 221 | -- | 222 | -- | Makes a new directory with all of its options. 223 | -- | 224 | mkdir' :: FilePath -> { recursive :: Boolean, mode :: Perms } -> Aff Unit 225 | mkdir' = toAff2 A.mkdir' 226 | 227 | -- | 228 | -- | Reads the contents of a directory. 229 | -- | 230 | readdir :: FilePath -> Aff (Array FilePath) 231 | readdir = toAff1 A.readdir 232 | 233 | -- | 234 | -- | Sets the accessed and modified times for the specified file. 235 | -- | 236 | utimes :: FilePath -> DateTime -> DateTime -> Aff Unit 237 | utimes = toAff3 A.utimes 238 | 239 | -- | 240 | -- | Reads the entire contents of a file returning the result as a raw buffer. 241 | -- | 242 | readFile :: FilePath -> Aff Buffer 243 | readFile = toAff1 A.readFile 244 | 245 | -- | 246 | -- | Reads the entire contents of a text file with the specified encoding. 247 | -- | 248 | readTextFile :: Encoding -> FilePath -> Aff String 249 | readTextFile = toAff2 A.readTextFile 250 | 251 | -- | 252 | -- | Writes a buffer to a file. 253 | -- | 254 | writeFile :: FilePath -> Buffer -> Aff Unit 255 | writeFile = toAff2 A.writeFile 256 | 257 | -- | 258 | -- | Writes text to a file using the specified encoding. 259 | -- | 260 | writeTextFile :: Encoding -> FilePath -> String -> Aff Unit 261 | writeTextFile = toAff3 A.writeTextFile 262 | 263 | -- | 264 | -- | Appends the contents of a buffer to a file. 265 | -- | 266 | appendFile :: FilePath -> Buffer -> Aff Unit 267 | appendFile = toAff2 A.appendFile 268 | 269 | -- | 270 | -- | Appends text to a file using the specified encoding. 271 | -- | 272 | appendTextFile :: Encoding -> FilePath -> String -> Aff Unit 273 | appendTextFile = toAff3 A.appendTextFile 274 | 275 | -- | Open a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback) 276 | -- | for details. 277 | fdOpen 278 | :: FilePath 279 | -> F.FileFlags 280 | -> Maybe F.FileMode 281 | -> Aff F.FileDescriptor 282 | fdOpen = toAff3 A.fdOpen 283 | 284 | -- | Read from a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) 285 | -- | for details. 286 | fdRead 287 | :: F.FileDescriptor 288 | -> Buffer 289 | -> F.BufferOffset 290 | -> F.BufferLength 291 | -> Maybe F.FilePosition 292 | -> Aff F.ByteCount 293 | fdRead = toAff5 A.fdRead 294 | 295 | -- | Convenience function to fill the whole buffer from the current 296 | -- | file position. 297 | fdNext :: F.FileDescriptor -> Buffer -> Aff F.ByteCount 298 | fdNext = toAff2 A.fdNext 299 | 300 | -- | Write to a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback) 301 | -- | for details. 302 | fdWrite 303 | :: F.FileDescriptor 304 | -> Buffer 305 | -> F.BufferOffset 306 | -> F.BufferLength 307 | -> Maybe F.FilePosition 308 | -> Aff F.ByteCount 309 | fdWrite = toAff5 A.fdWrite 310 | 311 | -- | Convenience function to append the whole buffer to the current 312 | -- | file position. 313 | fdAppend :: F.FileDescriptor -> Buffer -> Aff F.ByteCount 314 | fdAppend = toAff2 A.fdAppend 315 | 316 | -- | Close a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_close_fd_callback) 317 | -- | for details. 318 | fdClose :: F.FileDescriptor -> Aff Unit 319 | fdClose = toAff1 A.fdClose 320 | --------------------------------------------------------------------------------