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

Commit 9342917

Browse files
committed
Docs and CI
1 parent 56661a1 commit 9342917

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up a PureScript toolchain
16+
uses: purescript-contrib/setup-purescript@main
17+
with:
18+
purescript: "unstable"
19+
purs-tidy: "latest"
20+
21+
- name: Cache PureScript dependencies
22+
uses: actions/cache@v2
23+
with:
24+
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
25+
path: |
26+
.spago
27+
output
28+
- name: Install dependencies
29+
run: spago install
30+
31+
- name: Build source
32+
run: spago build --no-install --purs-args '--censor-lib --strict'
33+
34+
- name: Install dev dependencies
35+
run: spago -x spago-dev.dhall install
36+
37+
- name: Run tests
38+
run: spago -x spago-dev.dhall test --no-install --exec-args <(head --bytes 1000000 /dev/zero)
39+
40+
# - name: Check formatting
41+
# run: purs-tidy check src test
42+
43+
- name: Verify Bower & Pulp
44+
run: |
45+
npm install bower pulp@16.0.0-0
46+
npx bower install
47+
npx pulp build -- --censor-lib --strict

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

22
# 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)
5+
[![Pursuit](https://pursuit.purescript.org/packages/purescript-node-streams-aff/badge)](https://pursuit.purescript.org/packages/purescript-node-streams-aff)
6+
47
Asynchronous PureScript API for the [*Node.js* `stream` API](https://nodejs.org/docs/latest/api/stream.html).

src/Node/Stream/Aff.purs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ import Node.Stream.Aff.Internal (onceDrain, onceEnd, onceError, onceReadable)
9999

100100

101101
-- | Wait until there is some data available from the stream.
102+
-- |
103+
-- | This function is not currently very useful because there is no way to
104+
-- | know when the stream has reached its end, and if this
105+
-- | function is called after the stream has ended then the call will
106+
-- | never complete.
102107
readSome
103108
:: forall m r
104109
. MonadAff m
@@ -181,7 +186,10 @@ readAll_ r canceller = liftAff <<< makeAff $ \res -> do
181186
-- | Wait for *N* bytes to become available from the stream.
182187
-- |
183188
-- | If more than *N* bytes are available on the stream, then
184-
-- | only returns *N* bytes and leaves the rest in the stream’s internal buffer.
189+
-- | completes with *N* bytes and leaves the rest in the stream’s internal buffer.
190+
-- |
191+
-- | If the end of the stream is reached before *N* bytes are available,
192+
-- | then completes with less than *N* bytes.
185193
readN
186194
:: forall m r
187195
. MonadAff m
@@ -204,6 +212,8 @@ readN_ r canceller n = liftAff <<< makeAff $ \res -> do
204212

205213
onceError r $ res <<< Left
206214

215+
-- The `end` event is sometimes raised after we have read N bytes, even
216+
-- if there are more bytes in the stream?
207217
onceEnd r do
208218
ret <- liftST $ Array.ST.unsafeFreeze bufs
209219
res $ Right ret

test/Main.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
-- | How to test:
2+
-- |
23
-- | ```
34
-- | spago -x spago-dev.dhall test --exec-args <(head --bytes 1000000 /dev/zero)
45
-- | ```
56
-- |
7+
-- | We want to read from a file, not stdin, because stdin has no EOF.
68
module Test.Main where
79

810
import Prelude
@@ -27,8 +29,6 @@ import Test.Spec.Runner (runSpec)
2729

2830
main :: Effect Unit
2931
main = unsafePartial $ do
30-
-- We want to read from a file, not stdin, because stdin has no EOF.
31-
-- But we currently have no way to detect EOF.
3232
runAff_ (either (show >>> Console.log) (\_ -> pure unit)) $ runSpec [consoleReporter] do
3333
describe "Node.Stream.Aff" do
3434
it "reads 1" do
@@ -38,10 +38,11 @@ main = unsafePartial $ do
3838
shouldEqual 500000 bytesRead1
3939
inputs2 <- readSome infile
4040
inputs3 <- readAll infile
41-
-- TODO read after EOF hangs
41+
let inputs = inputs1 <> inputs2 <> inputs3
42+
-- TODO read after EOF will hang
4243
-- inputs4 <- readAll infile
4344
-- inputs4 <- readSome infile
44-
let inputs = inputs1 <> inputs2 <> inputs3
45+
-- inputs4 <- readN infile 10
4546
-- let inputs = inputs1 <> inputs2 <> inputs3 <> inputs4
4647
bytesRead :: Int
4748
<- liftEffect $ Array.foldM (\a b -> (a+_) <$> Buffer.size b) 0 inputs

0 commit comments

Comments
 (0)