Skip to content

Commit

Permalink
Merge pull request #34 from anilanar/ps-0.11
Browse files Browse the repository at this point in the history
update for purescript 0.11
  • Loading branch information
paf31 authored Apr 4, 2017
2 parents 7cae2f0 + a2b5fce commit d18a01f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 67 deletions.
22 changes: 11 additions & 11 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
"package.json"
],
"dependencies": {
"purescript-datetime": "^2.0.0",
"purescript-foreign": "^3.0.0",
"purescript-node-buffer": "^2.0.0",
"purescript-node-path": "^1.0.0",
"purescript-unsafe-coerce": "^2.0.0",
"purescript-nullable": "^2.0.0",
"purescript-node-streams": "^2.0.0",
"purescript-exceptions": "^2.0.0",
"purescript-js-date": "^3.0.0",
"purescript-globals": "^2.0.0"
"purescript-datetime": "^3.0.0",
"purescript-foreign": "^4.0.0",
"purescript-node-buffer": "^3.0.0",
"purescript-node-path": "^2.0.0",
"purescript-unsafe-coerce": "^3.0.0",
"purescript-nullable": "^3.0.0",
"purescript-node-streams": "^3.0.0",
"purescript-exceptions": "^3.0.0",
"purescript-js-date": "^4.0.0",
"purescript-globals": "^3.0.0"
},
"devDependencies": {
"purescript-console": "^2.0.0"
"purescript-console": "^3.0.0"
}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "jshint src && jscs src && pulp build --censor-lib --strict",
"build": "jshint src && jscs src && pulp build -- --censor-lib --strict",
"test": "pulp test"
},
"devDependencies": {
"jscs": "^3.0.7",
"jshint": "^2.9.2",
"pulp": "^9.0.1",
"purescript-psa": "^0.3.9",
"rimraf": "^2.5.4"
"jshint": "^2.9.4",
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"rimraf": "^2.6.1"
}
}
5 changes: 3 additions & 2 deletions src/Node/FS.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ module Node.FS
) where

import Prelude
import Control.Monad.Eff (kind Effect)

-- | Effect type for file system usage.
foreign import data FS :: !
foreign import data FS :: Effect

foreign import data FileDescriptor :: *
foreign import data FileDescriptor :: Type

data FileFlags = R | R_PLUS | RS | RS_PLUS
| W | WX | W_PLUS | WX_PLUS
Expand Down
64 changes: 32 additions & 32 deletions src/Node/FS/Sync.purs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ import Control.Monad.Eff.Exception (EXCEPTION)
import Data.DateTime (DateTime)
import Data.Time.Duration (Milliseconds(..))
import Data.DateTime.Instant (fromDateTime, unInstant)
import Data.Function.Uncurried (Fn1, Fn5, Fn3, Fn2,
import Data.Function.Uncurried (Fn1, Fn5, Fn3, Fn2,
runFn1, runFn5, runFn3, runFn2)
import Data.Nullable (Nullable(), toNullable)
import Data.Int (round)
import Data.Maybe (Maybe(..))
import Node.Buffer (Buffer(), BUFFER(), size)
import Node.Encoding (Encoding)

import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength,
BufferOffset, FileMode, FileFlags, SymlinkType,
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength,
BufferOffset, FileMode, FileFlags, SymlinkType,
fileFlagsToNode, symlinkTypeToNode)
import Node.FS.Stats (StatsObj, Stats(..))
import Node.Path (FilePath())
Expand Down Expand Up @@ -83,15 +83,15 @@ fs = unsafeRequireFS
-- | Renames a file.
rename :: forall eff. FilePath
-> FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

rename oldFile newFile = mkEff $ \_ -> runFn2
fs.renameSync oldFile newFile

-- | Truncates a file to the specified length.
truncate :: forall eff. FilePath
-> Int
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

truncate file len = mkEff $ \_ -> runFn2
fs.truncateSync file len
Expand All @@ -100,30 +100,30 @@ truncate file len = mkEff $ \_ -> runFn2
chown :: forall eff. FilePath
-> Int
-> Int
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

chown file uid gid = mkEff $ \_ -> runFn3
fs.chownSync file uid gid

-- | Changes the permissions of a file.
chmod :: forall eff. FilePath
-> Perms
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

chmod file perms = mkEff $ \_ -> runFn2
fs.chmodSync file (permsToString perms)

-- | Gets file statistics.
stat :: forall eff. FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) Stats
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Stats

stat file = map Stats $ mkEff $ \_ -> runFn1
fs.statSync file

-- | Creates a link to an existing file.
link :: forall eff. FilePath
-> FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

link src dst = mkEff $ \_ -> runFn2
fs.linkSync src dst
Expand All @@ -132,21 +132,21 @@ link src dst = mkEff $ \_ -> runFn2
symlink :: forall eff. FilePath
-> FilePath
-> SymlinkType
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

symlink src dst ty = mkEff $ \_ -> runFn3
fs.symlinkSync src dst (symlinkTypeToNode ty)

-- | Reads the value of a symlink.
readlink :: forall eff. FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) FilePath
-> Eff (fs :: FS, exception :: EXCEPTION | eff) FilePath

readlink path = mkEff $ \_ -> runFn1
fs.readlinkSync path

-- | Find the canonicalized absolute location for a path.
realpath :: forall eff. FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) FilePath
-> Eff (fs :: FS, exception :: EXCEPTION | eff) FilePath

realpath path = mkEff $ \_ -> runFn2
fs.realpathSync path {}
Expand All @@ -155,42 +155,42 @@ realpath path = mkEff $ \_ -> runFn2
-- | already resolved paths.
realpath' :: forall eff cache. FilePath
-> { | cache }
-> Eff (fs :: FS, err :: EXCEPTION | eff) FilePath
-> Eff (fs :: FS, exception :: EXCEPTION | eff) FilePath

realpath' path cache = mkEff $ \_ -> runFn2
fs.realpathSync path cache

-- | Deletes a file.
unlink :: forall eff. FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

unlink file = mkEff $ \_ -> runFn1
fs.unlinkSync file

-- | Deletes a directory.
rmdir :: forall eff. FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

rmdir file = mkEff $ \_ -> runFn1
fs.rmdirSync file

-- | Makes a new directory.
mkdir :: forall eff. FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

mkdir = flip mkdir' $ mkPerms all all all

-- | Makes a new directory with the specified permissions.
mkdir' :: forall eff. FilePath
-> Perms
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

mkdir' file perms = mkEff $ \_ -> runFn2
fs.mkdirSync file (permsToString perms)

-- | Reads the contents of a directory.
readdir :: forall eff. FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) (Array FilePath)
-> Eff (fs :: FS, exception :: EXCEPTION | eff) (Array FilePath)

readdir file = mkEff $ \_ -> runFn1
fs.readdirSync file
Expand All @@ -199,7 +199,7 @@ readdir file = mkEff $ \_ -> runFn1
utimes :: forall eff. FilePath
-> DateTime
-> DateTime
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

utimes file atime mtime = mkEff $ \_ -> runFn3
fs.utimesSync file
Expand All @@ -212,23 +212,23 @@ utimes file atime mtime = mkEff $ \_ -> runFn3

-- | Reads the entire contents of a file returning the result as a raw buffer.
readFile :: forall eff. FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) Buffer
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Buffer

readFile file = mkEff $ \_ -> runFn2
fs.readFileSync file {}

-- | Reads the entire contents of a text file with the specified encoding.
readTextFile :: forall eff. Encoding
-> FilePath
-> Eff (fs :: FS, err :: EXCEPTION | eff) String
-> Eff (fs :: FS, exception :: EXCEPTION | eff) String

readTextFile encoding file = mkEff $ \_ -> runFn2
fs.readFileSync file { encoding: show encoding }

-- | Writes a buffer to a file.
writeFile :: forall eff. FilePath
-> Buffer
-> Eff (buffer :: BUFFER, fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (buffer :: BUFFER, fs :: FS, exception :: EXCEPTION | eff) Unit

writeFile file buff = mkEff $ \_ -> runFn3
fs.writeFileSync file buff {}
Expand All @@ -237,15 +237,15 @@ writeFile file buff = mkEff $ \_ -> runFn3
writeTextFile :: forall eff. Encoding
-> FilePath
-> String
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

writeTextFile encoding file text = mkEff $ \_ -> runFn3
fs.writeFileSync file text { encoding: show encoding }

-- | Appends the contents of a buffer to a file.
appendFile :: forall eff. FilePath
-> Buffer
-> Eff (buffer :: BUFFER, fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (buffer :: BUFFER, fs :: FS, exception :: EXCEPTION | eff) Unit

appendFile file buff = mkEff $ \_ -> runFn3
fs.appendFileSync file buff {}
Expand All @@ -254,7 +254,7 @@ appendFile file buff = mkEff $ \_ -> runFn3
appendTextFile :: forall eff. Encoding
-> FilePath
-> String
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
-> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit

appendTextFile encoding file buff = mkEff $ \_ -> runFn3
fs.appendFileSync file buff { encoding: show encoding }
Expand All @@ -270,7 +270,7 @@ fdOpen :: forall eff.
FilePath
-> FileFlags
-> Maybe FileMode
-> Eff (err :: EXCEPTION, fs :: FS | eff) FileDescriptor
-> Eff (exception :: EXCEPTION, fs :: FS | eff) FileDescriptor
fdOpen file flags mode = mkEff $ \_ ->
runFn3 fs.openSync file (fileFlagsToNode flags) (toNullable mode)

Expand All @@ -282,7 +282,7 @@ fdRead :: forall eff.
-> BufferOffset
-> BufferLength
-> Maybe FilePosition
-> Eff (buffer :: BUFFER, err :: EXCEPTION, fs :: FS | eff) ByteCount
-> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount
fdRead fd buff off len pos =
mkEff $ \_ -> runFn5 fs.readSync fd buff off len (toNullable pos)

Expand All @@ -291,7 +291,7 @@ fdRead fd buff off len pos =
fdNext :: forall eff.
FileDescriptor
-> Buffer
-> Eff (buffer :: BUFFER, err :: EXCEPTION, fs :: FS | eff) ByteCount
-> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount
fdNext fd buff = do
sz <- size buff
fdRead fd buff 0 sz Nothing
Expand All @@ -304,7 +304,7 @@ fdWrite :: forall eff.
-> BufferOffset
-> BufferLength
-> Maybe FilePosition
-> Eff (buffer :: BUFFER, err :: EXCEPTION, fs :: FS | eff) ByteCount
-> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount
fdWrite fd buff off len pos =
mkEff $ \_ -> runFn5 fs.writeSync fd buff off len (toNullable pos)

Expand All @@ -313,7 +313,7 @@ fdWrite fd buff off len pos =
fdAppend :: forall eff.
FileDescriptor
-> Buffer
-> Eff (buffer :: BUFFER, err :: EXCEPTION, fs :: FS | eff) ByteCount
-> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount
fdAppend fd buff = do
sz <- size buff
fdWrite fd buff 0 sz Nothing
Expand All @@ -322,12 +322,12 @@ fdAppend fd buff = do
-- | for details.
fdFlush :: forall eff.
FileDescriptor
-> Eff (err :: EXCEPTION, fs :: FS | eff) Unit
-> Eff (exception :: EXCEPTION, fs :: FS | eff) Unit
fdFlush fd = mkEff $ \_ -> runFn1 fs.fsyncSync fd

-- | Close a file synchronously. See the [Node documentation](http://nodejs.org/api/fs.html#fs_fs_closesync_fd)
-- | for details.
fdClose :: forall eff.
FileDescriptor
-> Eff (err :: EXCEPTION, fs :: FS | eff) Unit
-> Eff (exception :: EXCEPTION, fs :: FS | eff) Unit
fdClose fd = mkEff $ \_ -> runFn1 fs.closeSync fd
4 changes: 2 additions & 2 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Test as Test
import TestAsync as TestAsync
import Test.Streams as Streams

main::forall e. Eff (fs :: FS , console :: CONSOLE ,
err :: EXCEPTION , buffer :: BUFFER | e) Unit
main::forall e. Eff (fs :: FS , console :: CONSOLE ,
exception :: EXCEPTION , buffer :: BUFFER | e) Unit
main = do
Test.main
TestAsync.main
Expand Down
6 changes: 3 additions & 3 deletions test/Streams.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import Node.FS (FS)
import Node.FS.Stream (createWriteStream, createReadStream)
import Node.FS.Sync as Sync

main::forall e. Eff (fs::FS, console::CONSOLE, err::EXCEPTION | e) Unit
main::forall e. Eff (fs::FS, console::CONSOLE, exception::EXCEPTION | e) Unit
main = do
let fp = Path.concat

log "Testing streams"
_ <- log "Testing streams"

r <- createReadStream (fp ["test", "Streams.purs"])
w <- createWriteStream (fp ["tmp", "Streams.purs"])

Stream.pipe r w
_ <- Stream.pipe r w

Stream.onEnd r do
src <- Sync.readTextFile UTF8 (fp ["test", "Streams.purs"])
Expand Down
Loading

0 comments on commit d18a01f

Please sign in to comment.