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

Commit 5cfc996

Browse files
committed
unbuffer
1 parent 0af1b14 commit 5cfc996

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

spago-dev.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ conf //
1919
, "node-fs"
2020
, "console"
2121
, "partial"
22+
, "unsafe-coerce"
2223
]
2324
, packages = packages_dev
2425
}

src/Node/Stream/Aff.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ module Node.Stream.Aff
8181
, readN_
8282
, write
8383
, write_
84+
, module Reexport
8485
)
8586

8687
where
@@ -102,6 +103,7 @@ import Node.Buffer as Buffer
102103
import Node.Stream (Readable, Writable)
103104
import Node.Stream as Stream
104105
import Node.Stream.Aff.Internal (onceDrain, onceEnd, onceError, onceReadable)
106+
import Node.Stream.Aff.Internal (unbuffer) as Reexport
105107

106108

107109
-- | Wait until there is some data available from the stream.

src/Node/Stream/Internal.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,32 @@ export function onceReadable(s) {
55
}
66

77
export function onceEnd(s) {
8-
return f => () => {
9-
s.once('end', f);
10-
};
8+
return f => () => {
9+
s.once('end', f);
10+
};
1111
}
1212

1313
export function onceDrain(s) {
14-
return f => () => {
15-
s.once('drain', f);
16-
};
14+
return f => () => {
15+
s.once('drain', f);
16+
};
1717
}
1818

1919
export function onceError(s) {
20-
return f => () => {
21-
s.once('error', f);
22-
};
20+
return f => () => {
21+
s.once('error', f);
22+
};
23+
}
24+
25+
export function unbuffer(s) {
26+
// // https://github.com/nodejs/node/issues/6456
27+
// return () => {
28+
// s && s.isTTY && s._handle && s._handle.setBlocking && s._handle.setBlocking(true);
29+
// };
30+
31+
// https://github.com/nodejs/node/issues/6379#issuecomment-1064044886
32+
return () => {
33+
// s && s._handle && s._handle.setBlocking && s._handle.setBlocking(true);
34+
s._handle.setBlocking(true);
35+
};
2336
}

src/Node/Stream/Internal.purs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Node.Stream.Aff.Internal
33
, onceEnd
44
, onceDrain
55
, onceError
6+
, unbuffer
67
)
78
where
89

@@ -40,4 +41,15 @@ foreign import onceError
4041
:: forall r
4142
. Stream r
4243
-> (Error -> Effect Unit)
43-
-> Effect Unit
44+
-> Effect Unit
45+
46+
-- | Issue:
47+
-- | https://github.com/nodejs/node/issues/6379
48+
-- |
49+
-- | Implementation:
50+
-- | https://github.com/nodejs/node/issues/6456
51+
foreign import unbuffer
52+
:: forall w
53+
. Writable w
54+
-> Effect Unit
55+
-- foreign import stdoutUnbuffer :: Effect Unit

test/Main.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import Test.Spec (describe, it)
2626
import Test.Spec.Assertions (shouldEqual)
2727
import Test.Spec.Reporter (consoleReporter)
2828
import Test.Spec.Runner (runSpec)
29+
import Unsafe.Coerce (unsafeCoerce)
2930

3031
main :: Effect Unit
3132
main = unsafePartial $ do
32-
runAff_ (either (show >>> Console.log) (\_ -> pure unit)) $ runSpec [consoleReporter] do
33+
runAff_ (either (unsafeCoerce >>> Console.error) (\_ -> pure unit)) $ runSpec [consoleReporter] do
3334
describe "Node.Stream.Aff" do
3435
it "reads 1" do
3536
infile <- liftEffect $ createReadStream =<< pure <<< flip Array.unsafeIndex 2 =<< argv

0 commit comments

Comments
 (0)