Skip to content

Update buffer dep; update CI; format #48

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"
purs-tidy: "latest"

- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: "14"
node-version: "lts/*"

- name: Install dependencies
run: |
Expand All @@ -33,3 +34,8 @@ jobs:
run: |
bower install
npm run-script test --if-present

- name: Check formatting
run: |
purs-tidy check src test

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ Notable changes to this project are documented in this file. The format is based
## [Unreleased]

Breaking changes:
- Update `node-buffer` to `v9.0.0` (#48 by @JordanMartinez)

New features:

Bugfixes:

Other improvements:
- Bumped CI's node version to `lts/*` (#48 by @JordanMartinez)
- Updated CI `actions/checkout` and `actions/setup-nodee` to `v3` (#48 by @JordanMartinez)
- Format code via purs-tidy; enforce formatting via CI (#48 by @JordanMartinez)

## [v7.0.0](https://github.com/purescript-node/purescript-node-streams/releases/tag/v7.0.0) - 2022-04-29

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"purescript-effect": "^4.0.0",
"purescript-either": "^6.0.0",
"purescript-exceptions": "^6.0.0",
"purescript-node-buffer": "^8.0.0",
"purescript-node-buffer": "^9.0.0",
"purescript-nullable": "^6.0.0",
"purescript-prelude": "^6.0.0"
}
Expand Down
16 changes: 8 additions & 8 deletions src/Node/Stream.purs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ onData r cb =
where
fromEither x =
case x of
Left _ ->
Left _ ->
throw "Stream encoding should not be set"
Right buf ->
pure buf

read
:: forall w
. Readable w
-> Maybe Int
-> Effect (Maybe Buffer)
-> Maybe Int
-> Effect (Maybe Buffer)
read r size = do
v <- readEither r size
case v of
Nothing -> pure Nothing
Just (Left _) -> throw "Stream encoding should not be set"
Nothing -> pure Nothing
Just (Left _) -> throw "Stream encoding should not be set"
Just (Right b) -> pure (Just b)

readString
Expand All @@ -121,9 +121,9 @@ readString
readString r size enc = do
v <- readEither r size
case v of
Nothing -> pure Nothing
Just (Left _) -> throw "Stream encoding should not be set"
Just (Right buf) -> Just <$> Buffer.toString enc buf
Nothing -> pure Nothing
Just (Left _) -> throw "Stream encoding should not be set"
Just (Right buf) -> Just <$> Buffer.toString enc buf

readEither
:: forall w
Expand Down
65 changes: 31 additions & 34 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ assertEqual :: forall a. Show a => Eq a => a -> a -> Effect Unit
assertEqual x y =
assert' (show x <> " did not equal " <> show y) (x == y)


foreign import writableStreamBuffer :: Effect (Writable ())

foreign import getContentsAsString :: forall r. Writable r -> Effect String
Expand Down Expand Up @@ -58,34 +57,34 @@ testReads = do
testReadBuf

where
testReadString = do
sIn <- passThrough
v <- readString sIn Nothing UTF8
assert (isNothing v)

onReadable sIn do
str <- readString sIn Nothing UTF8
assert (isJust str)
assertEqual (unsafePartial (fromJust str)) testString
pure unit

writeString sIn UTF8 testString \_ -> do
pure unit

testReadBuf = do
sIn <- passThrough
v <- read sIn Nothing
assert (isNothing v)

onReadable sIn do
buf <- read sIn Nothing
assert (isJust buf)
_ <- assertEqual <$> (Buffer.toString UTF8 (unsafePartial (fromJust buf)))
<*> pure testString
pure unit

writeString sIn UTF8 testString \_ -> do
pure unit
testReadString = do
sIn <- passThrough
v <- readString sIn Nothing UTF8
assert (isNothing v)

onReadable sIn do
str <- readString sIn Nothing UTF8
assert (isJust str)
assertEqual (unsafePartial (fromJust str)) testString
pure unit

writeString sIn UTF8 testString \_ -> do
pure unit

testReadBuf = do
sIn <- passThrough
v <- read sIn Nothing
assert (isNothing v)

onReadable sIn do
buf <- read sIn Nothing
assert (isJust buf)
_ <- assertEqual <$> (Buffer.toString UTF8 (unsafePartial (fromJust buf)))
<*> pure testString
pure unit

writeString sIn UTF8 testString \_ -> do
pure unit

testSetDefaultEncoding :: Effect Boolean
testSetDefaultEncoding = do
Expand Down Expand Up @@ -123,9 +122,9 @@ testSetEncoding = do

testPipe :: Effect Boolean
testPipe = do
sIn <- passThrough
sOut <- passThrough
zip <- createGzip
sIn <- passThrough
sOut <- passThrough
zip <- createGzip
unzip <- createGunzip

log "pipe 1"
Expand All @@ -140,11 +139,9 @@ testPipe = do
onDataString sOut UTF8 \str -> do
assertEqual str testString


foreign import createGzip :: Effect Duplex
foreign import createGunzip :: Effect Duplex


-- | Create a PassThrough stream, which simply writes its input to its output.
foreign import passThrough :: Effect Duplex

Expand Down