Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit f2102c7

Browse files
authored
Merge pull request #7 from purescript-node/cleaning
Transfer to purescript-node
2 parents 68bf051 + ff83be7 commit f2102c7

File tree

12 files changed

+82
-64
lines changed

12 files changed

+82
-64
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: CI
22

33
on:
44
push:
5+
branches: [main]
56
pull_request:
67
branches: [main]
78

@@ -37,8 +38,8 @@ jobs:
3738
- name: Run tests
3839
run: spago -x spago-dev.dhall test --no-install
3940

40-
# - name: Check formatting
41-
# run: purs-tidy check src test
41+
- name: Check formatting
42+
run: purs-tidy check src test
4243

4344
- name: Verify Bower & Pulp
4445
run: |

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Bugfixes:
1212

1313
Other improvements:
1414

15+
* Transferred to https://github.com/purescript-node org (#7 by @jamesdbrock)
16+
1517
## v4.0.0
1618

1719
Bugfixes:

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 PureScript, James Dawson Brock
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11

2-
# node-streams-aff
2+
# purescript-node-streams-aff
33

4-
[![CI](https://github.com/jamesdbrock/purescript-node-streams-aff/workflows/CI/badge.svg?branch=main)](https://github.com/jamesdbrock/purescript-node-streams-aff/actions?query=workflow%3ACI+branch%3Amain)
4+
[![Latest release](http://img.shields.io/github/release/purescript-node/purescript-node-streams-aff.svg)](https://github.com/purescript-node/purescript-node-streams-aff/releases)
5+
[![CI](https://github.com/purescript-node/purescript-node-streams-aff/workflows/CI/badge.svg?branch=main)](https://github.com/purescript-node/purescript-node-streams-aff/actions?query=workflow%3ACI+branch%3Amain)
56
[![Pursuit](https://pursuit.purescript.org/packages/purescript-node-streams-aff/badge)](https://pursuit.purescript.org/packages/purescript-node-streams-aff)
67

7-
Asynchronous PureScript API for [*Node.js* Stream](https://nodejs.org/docs/latest/api/stream.html).
8+
Asynchronous PureScript [`Aff`](https://pursuit.purescript.org/packages/purescript-aff) API for [*Node.js* Stream](https://nodejs.org/docs/latest/api/stream.html).
9+
10+
## Installation
11+
12+
```
13+
spago install node-streams-aff
14+
```
15+
16+
## Documentation
17+
18+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-node-streams-aff).
819

9-
## Prior art
1020

11-
* https://pursuit.purescript.org/packages/purescript-node-fs-aff/docs/Node.FS.Aff
12-
* https://pursuit.purescript.org/packages/purescript-node-fs/docs/Node.FS.Async
13-
* https://pursuit.purescript.org/packages/purescript-node-coroutines
14-
* https://pursuit.purescript.org/packages/purescript-idiomatic-node-stream
15-
* https://dgopsq.space/blog/reading-from-stdin-using-purescript
16-
* https://github.com/purescript-contrib/pulp/blob/master/src/Pulp/System/Stream.purs

packages.dhall

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ in upstream
9999
-------------------------------
100100
-}
101101
let upstream =
102-
https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220516/packages.dhall
103-
sha256:b0bf932de16a10b7d69c6bbbb31ec9ca575237c43a999fa32e59e35eb8c024a1
102+
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221013/packages.dhall
103+
sha256:21000b190e1ef14c92feb1400816022319bc40a30280d20f24c0dcacfb85e966
104104

105105
in upstream

spago.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ to generate this file without the comments in this block.
2929
, packages = ./packages.dhall
3030
, sources = [ "src/**/*.purs" ]
3131
, license = "MIT"
32-
, repository = "https://github.com/jamesdbrock/purescript-node-streams-aff.git"
32+
, repository = "https://github.com/purescript-node/purescript-node-streams-aff.git"
3333
}

src/Node/Stream/Aff.purs

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ module Node.Stream.Aff
8181
, end
8282
, toStringUTF8
8383
, fromStringUTF8
84-
)
85-
where
84+
) where
8685

8786
import Prelude
8887

@@ -105,7 +104,6 @@ import Node.Stream (Readable, Writable)
105104
import Node.Stream as Stream
106105
import Node.Stream.Aff.Internal (onceDrain, onceEnd, onceError, onceReadable, readable)
107106

108-
109107
-- | Wait until there is some data available from the stream, then read it.
110108
-- |
111109
-- | This function is useful for streams like __stdin__ which never
@@ -140,44 +138,43 @@ readSome r = liftAff <<< makeAff $ \res -> do
140138
removeEnd
141139
res (Right (Tuple [] false))
142140

143-
144141
ret1 <- liftST $ Array.ST.unsafeFreeze bufs
145142
readagain <- readable r
146-
removeReadable <- if readagain && Array.length ret1 == 0 then do
147-
-- if still readable and we couldn't read anything right away,
148-
-- then wait for the readable event.
149-
-- “The 'readable' event will also be emitted once the end of the
150-
-- stream data has been reached but before the 'end' event is emitted.”
151-
-- if not readable then this was a zero-length Readable stream.
152-
-- https://nodejs.org/api/stream.html#event-readable
153-
onceReadable r do
154-
catchException (res <<< Left) do
155-
untilE do
156-
Stream.read r Nothing >>= case _ of
157-
Nothing -> pure true
158-
Just chunk -> do
159-
void $ liftST $ Array.ST.push chunk bufs
160-
pure false
161-
ret2 <- liftST $ Array.ST.unsafeFreeze bufs
162-
removeError
163-
removeEnd
164-
readagain2 <- readable r
165-
res (Right (Tuple ret2 readagain2))
143+
removeReadable <-
144+
if readagain && Array.length ret1 == 0 then do
145+
-- if still readable and we couldn't read anything right away,
146+
-- then wait for the readable event.
147+
-- “The 'readable' event will also be emitted once the end of the
148+
-- stream data has been reached but before the 'end' event is emitted.”
149+
-- if not readable then this was a zero-length Readable stream.
150+
-- https://nodejs.org/api/stream.html#event-readable
151+
onceReadable r do
152+
catchException (res <<< Left) do
153+
untilE do
154+
Stream.read r Nothing >>= case _ of
155+
Nothing -> pure true
156+
Just chunk -> do
157+
void $ liftST $ Array.ST.push chunk bufs
158+
pure false
159+
ret2 <- liftST $ Array.ST.unsafeFreeze bufs
160+
removeError
161+
removeEnd
162+
readagain2 <- readable r
163+
res (Right (Tuple ret2 readagain2))
166164

167165
-- return what we read right away
168-
else do
169-
removeError
170-
removeEnd
171-
res (Right (Tuple ret1 readagain))
172-
pure (pure unit) -- dummy canceller
166+
else do
167+
removeError
168+
removeEnd
169+
res (Right (Tuple ret1 readagain))
170+
pure (pure unit) -- dummy canceller
173171

174172
-- canceller might by called while waiting for `onceReadable`
175173
pure $ effectCanceler do
176174
removeError
177175
removeEnd
178176
removeReadable
179177

180-
181178
-- | Read all data until the end of the stream.
182179
-- |
183180
-- | Note that __stdin__ will never end.
@@ -243,7 +240,6 @@ readAll r = liftAff <<< makeAff $ \res -> do
243240
removeEnd
244241
join $ Ref.read removeReadable
245242

246-
247243
-- | Wait for *N* bytes to become available from the stream.
248244
-- |
249245
-- | If more than *N* bytes are available on the stream, then
@@ -288,12 +284,12 @@ readN r n = liftAff <<< makeAff $ \res -> do
288284
-- “If size bytes are not available to be read, null will be returned
289285
-- unless the stream has ended, in which case all of the data remaining
290286
-- in the internal buffer will be returned.”
291-
Stream.read r (Just (n-red)) >>= case _ of
287+
Stream.read r (Just (n - red)) >>= case _ of
292288
Nothing -> pure true
293289
Just chunk -> do
294290
_ <- liftST $ Array.ST.push chunk bufs
295291
s <- Buffer.size chunk
296-
red' <- Ref.modify (_+s) redRef
292+
red' <- Ref.modify (_ + s) redRef
297293
if red' >= n then
298294
pure true
299295
else
@@ -331,7 +327,6 @@ readN r n = liftAff <<< makeAff $ \res -> do
331327
removeEnd
332328
join $ Ref.read removeReadable
333329

334-
335330
-- | Write to a stream.
336331
-- |
337332
-- | Will complete after the data is flushed to the stream.
@@ -368,7 +363,7 @@ write w bs = liftAff <<< makeAff $ \res -> do
368363
Nothing -> do
369364
pure true
370365
Just chunk -> do
371-
isLast <- liftST $ (_==0) <$> Array.length <$> Array.ST.unsafeFreeze bufs
366+
isLast <- liftST $ (_ == 0) <$> Array.length <$> Array.ST.unsafeFreeze bufs
372367
nobackpressure <- Stream.write w chunk (if isLast then callbackLast else callback)
373368
if nobackpressure then do
374369
pure false
@@ -403,7 +398,7 @@ end w = liftAff <<< makeAff $ \res -> do
403398
Just err -> res (Left err)
404399
pure $ nonCanceler
405400

406-
-- | Concatenate an `Array` of UTF-8 encoded `Buffer`s into a `String`.
401+
-- | Concatenate an `Array` of UTF-8 encoded `Buffer`s into a `String`.
407402
toStringUTF8 :: forall m. MonadEffect m => Array Buffer -> m String
408403
toStringUTF8 bs = liftEffect $ Buffer.toString Encoding.UTF8 =<< Buffer.concat bs
409404

src/Node/Stream/Internal.purs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ module Node.Stream.Aff.Internal
1010
, push
1111
, newReadable
1212
, newReadableStringUTF8
13-
)
14-
where
13+
) where
1514

1615
import Prelude
1716

@@ -77,7 +76,6 @@ foreign import readable
7776
. Readable r
7877
-> Effect Boolean
7978

80-
8179
-- | [`readable.push(chunk[, encoding])`](https://nodejs.org/api/stream.html#readablepushchunk-encoding)
8280
foreign import push
8381
:: forall r

test/Main.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Test.Spec.Runner (defaultConfig, runSpec')
3030
main :: Effect Unit
3131
main = unsafePartial $ do
3232
launchAff_ do
33-
runSpec' (defaultConfig {timeout = Just (Milliseconds 20000.0)}) [consoleReporter] do
33+
runSpec' (defaultConfig { timeout = Just (Milliseconds 40000.0) }) [ consoleReporter ] do
3434
describe "Node.Stream.Aff" do
3535
it "writes and reads" do
3636
let outfilename = "/tmp/test1.txt"
@@ -54,9 +54,9 @@ main = unsafePartial $ do
5454
let outfilename = "/tmp/test2.txt"
5555
outfile <- liftEffect $ createWriteStream outfilename
5656
b <- liftEffect $ Buffer.fromString "test" UTF8
57-
write outfile [b]
57+
write outfile [ b ]
5858
end outfile
59-
expectError $ write outfile [b]
59+
expectError $ write outfile [ b ]
6060
it "reads from a zero-length Readable" do
6161
r <- liftEffect $ newReadableStringUTF8 ""
6262
b1 <- toStringUTF8 =<< (fst <$> readSome r)

test/Main2.purs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ completion = case _ of
2525
Left e -> Console.error (unsafeCoerce e)
2626
Right f -> f
2727

28-
2928
main :: Effect Unit
3029
main = unsafePartial $ do
3130
runAff_ completion do

test/Main3.purs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ completion = case _ of
3434
main :: Effect Unit
3535
main = unsafePartial $ do
3636
runAff_ completion do
37-
runSpec [consoleReporter] do
37+
runSpec [ consoleReporter ] do
3838
describe "Node.Stream.Aff" do
3939
it "reads 1" do
4040
infile <- liftEffect $ createReadStream =<< pure <<< flip Array.unsafeIndex 2 =<< argv
4141
Tuple inputs1 _ <- readN infile 500000
42-
bytesRead1 :: Int <- liftEffect $ Array.foldM (\a b -> (a+_) <$> Buffer.size b) 0 inputs1
42+
bytesRead1 :: Int <- liftEffect $ Array.foldM (\a b -> (a + _) <$> Buffer.size b) 0 inputs1
4343
shouldEqual 500000 bytesRead1
4444
Tuple inputs2 _ <- readSome infile
4545
Tuple inputs3 _ <- readAll infile
@@ -49,8 +49,7 @@ main = unsafePartial $ do
4949
-- inputs4 <- readSome infile
5050
-- inputs4 <- readN infile 10
5151
-- let inputs = inputs1 <> inputs2 <> inputs3 <> inputs4
52-
bytesRead :: Int
53-
<- liftEffect $ Array.foldM (\a b -> (a+_) <$> Buffer.size b) 0 inputs
52+
bytesRead :: Int <- liftEffect $ Array.foldM (\a b -> (a + _) <$> Buffer.size b) 0 inputs
5453
shouldEqual 1000000 bytesRead
5554
input :: Buffer <- liftEffect $ concat inputs
5655
inputSize <- liftEffect $ Buffer.size input

test/Main4.purs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ completion = case _ of
2828
Left e -> Console.error (unsafeCoerce e)
2929
Right f -> f
3030

31-
3231
main :: Effect Unit
3332
main = unsafePartial $ do
3433
runAff_ completion do
35-
runSpec [consoleReporter] do
34+
runSpec [ consoleReporter ] do
3635
describe "Node.Stream.Aff" do
3736
it "reads 1" do
3837
sequential $ alt

0 commit comments

Comments
 (0)