Skip to content

Commit 30f299c

Browse files
committed
Initial commit
0 parents  commit 30f299c

File tree

8 files changed

+492
-0
lines changed

8 files changed

+492
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/bower_components/
2+
/node_modules/
3+
/output/
4+
/.psci*
5+
/src/.webpack.js

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 DICOM Grid, Inc.
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.

bower.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "purescript-node-streams",
3+
"moduleType": [
4+
"node"
5+
],
6+
"ignore": [
7+
"**/.*",
8+
"node_modules",
9+
"bower_components",
10+
"output"
11+
],
12+
"devDependencies": {
13+
"purescript-console": "^0.1.0"
14+
},
15+
"dependencies": {
16+
"purescript-eff": "~0.1.1",
17+
"purescript-node-buffer": "~0.1.0",
18+
"purescript-prelude": "~0.1.2"
19+
}
20+
}

docs/Node/Stream.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
## Module Node.Stream
2+
3+
This module provides a low-level wrapper for the Node Stream API.
4+
5+
#### `Stream`
6+
7+
``` purescript
8+
data Stream :: # * -> # ! -> * -> *
9+
```
10+
11+
A stream.
12+
13+
The type arguments track, in order:
14+
15+
- Whether reading and/or writing from/to the stream are allowed.
16+
- Effects associated with reading/writing from/to this stream.
17+
- The type of chunks which will be read from/written to this stream (`String` or `Buffer`).
18+
19+
#### `Read`
20+
21+
``` purescript
22+
data Read
23+
```
24+
25+
A phantom type associated with _readable streams_.
26+
27+
#### `Readable`
28+
29+
``` purescript
30+
type Readable r = Stream (read :: Read | r)
31+
```
32+
33+
A readable stream.
34+
35+
#### `Write`
36+
37+
``` purescript
38+
data Write
39+
```
40+
41+
A phantom type associated with _writable streams_.
42+
43+
#### `Writable`
44+
45+
``` purescript
46+
type Writable r = Stream (write :: Write | r)
47+
```
48+
49+
A writable stream.
50+
51+
#### `Duplex`
52+
53+
``` purescript
54+
type Duplex = Stream (read :: Read, write :: Write)
55+
```
56+
57+
A duplex (readable _and_ writable stream)
58+
59+
#### `setEncoding`
60+
61+
``` purescript
62+
setEncoding :: forall w eff. Readable w eff String -> Encoding -> Eff eff Unit
63+
```
64+
65+
Set the encoding used to read chunks from the stream.
66+
67+
#### `onData`
68+
69+
``` purescript
70+
onData :: forall w eff a. Readable w eff a -> (a -> Eff eff Unit) -> Eff eff Unit
71+
```
72+
73+
Listen for `data` events.
74+
75+
#### `onEnd`
76+
77+
``` purescript
78+
onEnd :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit
79+
```
80+
81+
Listen for `end` events.
82+
83+
#### `onClose`
84+
85+
``` purescript
86+
onClose :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit
87+
```
88+
89+
Listen for `close` events.
90+
91+
#### `onError`
92+
93+
``` purescript
94+
onError :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit
95+
```
96+
97+
Listen for `error` events.
98+
99+
#### `resume`
100+
101+
``` purescript
102+
resume :: forall w eff a. Readable w eff a -> Eff eff Unit
103+
```
104+
105+
Resume reading from the stream.
106+
107+
#### `pause`
108+
109+
``` purescript
110+
pause :: forall w eff a. Readable w eff a -> Eff eff Unit
111+
```
112+
113+
Pause reading from the stream.
114+
115+
#### `isPaused`
116+
117+
``` purescript
118+
isPaused :: forall w eff a. Readable w eff a -> Eff eff Boolean
119+
```
120+
121+
Check whether or not a stream is paused for reading.
122+
123+
#### `pipe`
124+
125+
``` purescript
126+
pipe :: forall r w eff a. Readable w eff a -> Writable r eff a -> Eff eff (Writable r eff a)
127+
```
128+
129+
Read chunks from a readable stream and write them to a writable stream.
130+
131+
#### `write`
132+
133+
``` purescript
134+
write :: forall r eff a. Writable r eff String -> a -> Eff eff Unit -> Eff eff Boolean
135+
```
136+
137+
Write a chunk to a writable stream.
138+
139+
#### `writeString`
140+
141+
``` purescript
142+
writeString :: forall r eff a. Writable r eff String -> Encoding -> String -> Eff eff Unit -> Eff eff Boolean
143+
```
144+
145+
Write a string in the specified encoding to a writable stream.
146+
147+
#### `cork`
148+
149+
``` purescript
150+
cork :: forall r eff a. Writable r eff a -> Eff eff Unit
151+
```
152+
153+
Force buffering of writes.
154+
155+
#### `uncork`
156+
157+
``` purescript
158+
uncork :: forall r eff a. Writable r eff a -> Eff eff Unit
159+
```
160+
161+
Flush buffered data.
162+
163+
#### `setDefaultEncoding`
164+
165+
``` purescript
166+
setDefaultEncoding :: forall r eff. Writable r eff String -> Encoding -> Eff eff Unit
167+
```
168+
169+
Set the default encoding used to write chunks to the stream.
170+
171+
#### `end`
172+
173+
``` purescript
174+
end :: forall r eff a. Writable r eff a -> Eff eff Unit -> Eff eff Unit
175+
```
176+
177+
End writing data to the stream.
178+
179+

src/Node/Stream.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
"use strict";
2+
3+
// module Node.Stream
4+
5+
exports.setEncodingImpl = function(s) {
6+
return function(enc) {
7+
return function() {
8+
s.setEncoding(enc);
9+
};
10+
};
11+
};
12+
13+
exports.onData = function(r) {
14+
return function(f) {
15+
return function() {
16+
s.on('data', function(chunk) {
17+
f(chunk)();
18+
});
19+
};
20+
};
21+
};
22+
23+
exports.onEnd = function(r) {
24+
return function(f) {
25+
return function() {
26+
s.on('end', function() {
27+
f();
28+
});
29+
};
30+
};
31+
};
32+
33+
exports.onError = function(r) {
34+
return function(f) {
35+
return function() {
36+
s.on('error', function() {
37+
f();
38+
});
39+
};
40+
};
41+
};
42+
43+
exports.onClose = function(r) {
44+
return function(f) {
45+
return function() {
46+
s.on('close', function() {
47+
f();
48+
});
49+
};
50+
};
51+
};
52+
53+
exports.resume = function(s) {
54+
return function() {
55+
s.resume();
56+
};
57+
};
58+
59+
exports.pause = function(s) {
60+
return function() {
61+
s.pause();
62+
};
63+
};
64+
65+
exports.isPaused = function(s) {
66+
return function() {
67+
return s.isPaused();
68+
};
69+
};
70+
71+
exports.pipe = function(r) {
72+
return function(w) {
73+
return function() {
74+
return r.pipe(w);
75+
};
76+
};
77+
};
78+
79+
exports.write = function(w) {
80+
return function(chunk) {
81+
return function(done) {
82+
return function() {
83+
return w.write(chunk, null, done);
84+
};
85+
};
86+
};
87+
};
88+
89+
exports.writeStringImpl = function(w) {
90+
return function(enc) {
91+
return function(s) {
92+
return function(done) {
93+
return function() {
94+
return w.write(s, enc, done);
95+
};
96+
};
97+
};
98+
};
99+
};
100+
101+
exports.cork = function(w) {
102+
return function() {
103+
return w.cork();
104+
};
105+
};
106+
107+
exports.uncork = function(w) {
108+
return function() {
109+
return w.uncork();
110+
};
111+
};
112+
113+
exports.setDefaultEncodingImpl = function(w) {
114+
return function(enc) {
115+
return function() {
116+
w.setDefaultEncoding(enc);
117+
};
118+
};
119+
};
120+
121+
exports.end = function(w) {
122+
return function(done) {
123+
return function() {
124+
w.end(null, null, function() {
125+
f();
126+
});
127+
};
128+
};
129+
};

0 commit comments

Comments
 (0)