Skip to content

Commit e7fefe0

Browse files
committed
Initial commit
0 parents  commit e7fefe0

14 files changed

+256
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/generated-docs/
6+
/.psc-package/
7+
/.psc*
8+
/.purs*
9+
/.psa*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Awake Security
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, 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,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# purescript-web-streams

bower.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "purescript-web-streams",
3+
"homepage": "https://github.com/purescript-web/purescript-web-streams",
4+
"license": "MIT",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/purescript-web/purescript-web-streams.git"
8+
},
9+
"ignore": [
10+
"**/.*",
11+
"bower_components",
12+
"node_modules",
13+
"output",
14+
"bower.json",
15+
"package.json"
16+
],
17+
"dependencies": {
18+
"purescript-prelude": "^4.0.0",
19+
"purescript-effect": "^2.0.0",
20+
"purescript-nullable": "^4.0.0",
21+
"purescript-arraybuffer-types": "^2.0.0",
22+
"purescript-tuples": "^5.0.0",
23+
"purescript-web-promise": "https://github.com/purescript-web/purescript-web-promise.git#^1.0.0"
24+
}
25+
}

src/Web/Streams/QueuingStrategy.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exports.new = function(options) {
2+
return function() {
3+
return new QueuingStrategy(options);
4+
};
5+
};
6+
7+
exports.byteLengthQueuingStrategy = function(options) {
8+
return function() {
9+
return new ByteLengthQueuingStrategy(options);
10+
};
11+
};
12+
13+
exports.countQueuingStrategy = function(options) {
14+
return function() {
15+
return new CountQueuingStrategy(options);
16+
};
17+
};

src/Web/Streams/QueuingStrategy.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Web.Streams.QueuingStrategy where
2+
3+
import Data.ArrayBuffer.Types (Uint8Array)
4+
import Effect (Effect)
5+
6+
foreign import data QueuingStrategy :: Type -> Type
7+
8+
foreign import new :: forall chunk. { size :: chunk -> Int, highWaterMark :: Int } -> Effect (QueuingStrategy chunk)
9+
10+
foreign import byteLengthQueuingStrategy :: { highWaterMark :: Int } -> Effect (QueuingStrategy Uint8Array)
11+
12+
foreign import countQueuingStrategy :: forall a. { highWaterMark :: Int } -> Effect (QueuingStrategy a)

src/Web/Streams/ReadableStream.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
exports._new = function(source, strategy) {
2+
return new ReadableStream(source, strategy);
3+
};
4+
5+
exports.cancel = function(stream) {
6+
return function() {
7+
return stream.cancel();
8+
};
9+
};
10+
11+
exports.locked = function(stream) {
12+
return function() {
13+
return stream.locked;
14+
};
15+
};
16+
17+
exports.getReader = function(stream) {
18+
return function() {
19+
return stream.getReader();
20+
};
21+
};
22+
23+
exports._tee = function(tuple, stream) {
24+
var r = stream.tee();
25+
return tuple(r[0])(r[1]);
26+
};

src/Web/Streams/ReadableStream.purs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module Web.Streams.ReadableStream
2+
( ReadableStream
3+
, new
4+
, cancel
5+
, locked
6+
, getReader
7+
, tee
8+
) where
9+
10+
import Data.Maybe (Maybe)
11+
import Data.Nullable (Nullable, toNullable)
12+
import Data.Tuple (Tuple(..))
13+
import Effect (Effect)
14+
import Effect.Uncurried (EffectFn2, runEffectFn2)
15+
import Prelude (Unit)
16+
import Web.Promise (Promise)
17+
import Web.Streams.QueuingStrategy (QueuingStrategy)
18+
import Web.Streams.Reader (Reader)
19+
import Web.Streams.Source (Source)
20+
21+
foreign import data ReadableStream :: Type -> Type
22+
23+
foreign import _new :: forall chunk. EffectFn2 (Source chunk) (Nullable (QueuingStrategy chunk)) (ReadableStream chunk)
24+
25+
foreign import cancel :: forall chunk. ReadableStream chunk -> Effect (Promise Unit)
26+
27+
foreign import locked :: forall chunk. ReadableStream chunk -> Effect Boolean
28+
29+
foreign import getReader :: forall chunk. ReadableStream chunk -> Effect (Reader chunk)
30+
31+
foreign import _tee :: forall chunk. EffectFn2 (forall a b. a -> b -> Tuple a b) (ReadableStream chunk) (Tuple (ReadableStream chunk) (ReadableStream chunk))
32+
33+
new :: forall chunk. Source chunk -> Maybe (QueuingStrategy chunk) -> Effect (ReadableStream chunk)
34+
new source strategy = runEffectFn2 _new source (toNullable strategy)
35+
36+
tee :: forall chunk. ReadableStream chunk -> Effect (Tuple (ReadableStream chunk) (ReadableStream chunk))
37+
tee = runEffectFn2 _tee Tuple
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
exports.enqueue = function(chunk) {
2+
return function(controller) {
3+
return function() {
4+
return controller.enqueue(chunk);
5+
};
6+
};
7+
};
8+
9+
exports.close = function(controller) {
10+
return function() {
11+
return controller.close();
12+
};
13+
};
14+
15+
exports.error = function(error) {
16+
return function(controller) {
17+
return function() {
18+
return controller.error(error);
19+
};
20+
};
21+
};
22+
23+
exports.desiredSize = function(controller) {
24+
return function() {
25+
return controller.desiredSize;
26+
};
27+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Web.Streams.ReadableStreamController where
2+
3+
import Effect (Effect)
4+
import Error (Error)
5+
import Prelude (Unit)
6+
7+
foreign import data ReadableStreamController :: Type -> Type
8+
9+
foreign import enqueue :: forall chunk. chunk -> ReadableStreamController chunk -> Effect Unit
10+
11+
foreign import close :: forall chunk. ReadableStreamController chunk -> Effect Unit
12+
13+
foreign import error :: forall chunk. Error -> ReadableStreamController chunk -> Effect Unit
14+
15+
foreign import desiredSize :: forall chunk. ReadableStreamController chunk -> Effect Int

0 commit comments

Comments
 (0)