Skip to content

Commit

Permalink
feat: add it-byte-stream, it-length-prefixed-stream and it-protobuf-s…
Browse files Browse the repository at this point in the history
…tream

Add modules designed to make working with streams easier.
  • Loading branch information
achingbrain committed Jul 3, 2023
1 parent cc96001 commit 8271623
Show file tree
Hide file tree
Showing 31 changed files with 1,700 additions and 6 deletions.
41 changes: 40 additions & 1 deletion .github/workflows/js-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: ipfs/aegir/actions/cache-node-modules@master
- run: npm run --if-present lint
- run: npm run --if-present dep-check
- run: npm run --if-present doc-check

test-node:
needs: check
Expand Down Expand Up @@ -93,6 +94,44 @@ jobs:
with:
flags: firefox-webworker

test-webkit:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
node: [lts/*]
fail-fast: true
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- run: npm run --if-present test:webkit
- uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
with:
flags: webkit

test-webkit-webworker:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
node: [lts/*]
fail-fast: true
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- run: npm run --if-present test:webkit-webworker
- uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
with:
flags: webkit-webworker

test-electron-main:
needs: check
runs-on: ubuntu-latest
Expand Down Expand Up @@ -122,7 +161,7 @@ jobs:
flags: electron-renderer

release:
needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer]
needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-webkit, test-webkit-webworker, test-electron-main, test-electron-renderer]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [`/packages/it-batch`](./packages/it-batch) Takes an async iterator that emits things and emits them as fixed size batches
- [`/packages/it-batched-bytes`](./packages/it-batched-bytes) Takes an async iterator that emits byte arrays and emits them as fixed size batches
- [`/packages/it-buffer-stream`](./packages/it-buffer-stream) An async iterator that emits buffers containing bytes up to a certain length
- [`/packages/it-byte-stream`](./packages/it-byte-stream) Read and write arbitrary bytes over a duplex stream
- [`/packages/it-drain`](./packages/it-drain) Empties an async iterator
- [`/packages/it-filter`](./packages/it-filter) Filters the passed iterable by using the filter function
- [`/packages/it-first`](./packages/it-first) Returns the first result from an async iterator
Expand All @@ -27,13 +28,15 @@
- [`/packages/it-glob`](./packages/it-glob) Async iterable filename pattern matcher
- [`/packages/it-last`](./packages/it-last) Returns the last result from an async iterator
- [`/packages/it-length`](./packages/it-length) Counts the number of items in an async iterable
- [`/packages/it-length-prefixed-stream`](./packages/it-length-prefixed-stream) Read and write length-prefixed byte arrays over a duplex stream
- [`/packages/it-map`](./packages/it-map) Maps the values yielded by an async iterator
- [`/packages/it-merge`](./packages/it-merge) Treat one or more iterables as a single iterable
- [`/packages/it-multipart`](./packages/it-multipart) Async iterable http multipart message parser
- [`/packages/it-ndjson`](./packages/it-ndjson) Parse iterators as ndjson and transform iterators to ndjson
- [`/packages/it-parallel`](./packages/it-parallel) Takes an (async) iterable that emits promise-returning functions, invokes them in parallel up to the concurrency limit and emits the results as they become available, optionally in the same order as the input
- [`/packages/it-parallel-batch`](./packages/it-parallel-batch) Takes an async iterator that emits promise-returning functions, invokes them in parallel and emits the results in the same order as the input
- [`/packages/it-peekable`](./packages/it-peekable) Allows peeking/pushing an iterable
- [`/packages/it-protobuf-stream`](./packages/it-protobuf-stream) Read and write protobuf messages over a duplex stream
- [`/packages/it-reduce`](./packages/it-reduce) Reduces the values yielded from an async iterator
- [`/packages/it-skip`](./packages/it-skip) Skip items from an iterable
- [`/packages/it-sort`](./packages/it-sort) Collects all values from an async iterator, sorts them using the passed function and yields them
Expand All @@ -52,4 +55,3 @@ Licensed under either of
## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
"bugs": {
"url": "https://github.com/achingbrain/it/issues"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"private": true,
"scripts": {
"reset": "aegir run clean && aegir clean ./node_modules ./package-lock.json packages/*/node_modules packages/*/package-lock.json packages/*/dist",
Expand All @@ -29,6 +25,10 @@
"devDependencies": {
"aegir": "^39.0.2"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"workspaces": [
"packages/*"
]
Expand Down
4 changes: 4 additions & 0 deletions packages/it-byte-stream/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This project is dual licensed under MIT and Apache-2.0.

MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0
5 changes: 5 additions & 0 deletions packages/it-byte-stream/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
19 changes: 19 additions & 0 deletions packages/it-byte-stream/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
68 changes: 68 additions & 0 deletions packages/it-byte-stream/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# it-byte-stream <!-- omit in toc -->

[![codecov](https://img.shields.io/codecov/c/github/achingbrain/it.svg?style=flat-square)](https://codecov.io/gh/achingbrain/it)
[![CI](https://img.shields.io/github/actions/workflow/status/achingbrain/it/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/achingbrain/it/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)

> Read and write arbitrary bytes over a duplex stream
## Table of contents <!-- omit in toc -->

- [Install](#install)
- [Browser `<script>` tag](#browser-script-tag)
- [Usage](#usage)
- [License](#license)
- [Contribution](#contribution)

## Install

```console
$ npm i it-byte-stream
```

### Browser `<script>` tag

Loading this module through a script tag will make it's exports available as `ItByteStream` in the global namespace.

```html
<script src="https://unpkg.com/it-byte-stream/dist/index.min.js"></script>
```

- [Install](#install)
- [Browser `<script>` tag](#browser-script-tag)
- [Usage](#usage)
- [License](#license)
- [Contribution](#contribution)

```sh
> npm install it-pb-stream
```

## Usage

```js
import { byteStream } from 'it-byte-stream'

const stream = byteStream(duplex)

// read next available chunk
await stream.read()

// read next 5 bytes only
await stream.read(5)

// write a Uint8Array
await stream.write(buf)

//.. etc
```

## License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
143 changes: 143 additions & 0 deletions packages/it-byte-stream/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"name": "it-byte-stream",
"version": "0.0.0",
"description": "Read and write arbitrary bytes over a duplex stream",
"author": "Alex Potsides <alex@achingbrain.net>",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/achingbrain/it/tree/master/packages/it-byte-stream#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/achingbrain/it.git"
},
"bugs": {
"url": "https://github.com/achingbrain/it/issues"
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
"src",
"dist",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"sourceType": "module"
}
},
"release": {
"branches": [
"master"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"type": "deps",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "deps",
"section": "Dependencies"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
},
"scripts": {
"build": "aegir build",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"clean": "aegir clean",
"test": "aegir test",
"test:node": "aegir test -t node --cov",
"test:chrome": "aegir test -t browser --cov",
"test:chrome-webworker": "aegir test -t webworker",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"release": "aegir release"
},
"dependencies": {
"it-pushable": "^3.2.0",
"it-stream-types": "^2.0.1",
"uint8arraylist": "^2.4.1"
},
"devDependencies": {
"aegir": "^39.0.2",
"it-pair": "^2.0.2",
"uint8arrays": "^4.0.2"
}
}
Loading

0 comments on commit 8271623

Please sign in to comment.