Skip to content

Commit

Permalink
Fix _destroy implementation (#19)
Browse files Browse the repository at this point in the history
Also, add tests for Node.js stream conversions

Co-authored-by: larabr <[email protected]>
  • Loading branch information
hs-kgoriunov and larabr authored Oct 11, 2023
1 parent 2afee91 commit 884ed5d
Show file tree
Hide file tree
Showing 7 changed files with 2,427 additions and 93 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Test on Node.js

on:
push:
branches: [openpgpjs_v5]
pull_request:
branches: [openpgpjs_v5]

jobs:
build:
name: ${{ matrix.node-version }}

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
10 changes: 5 additions & 5 deletions .github/workflows/test-type-definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Types

on:
push:
branches: [main]
branches: [main, openpgpjs_v5]
pull_request:
branches: [main]
branches: [main, openpgpjs_v5]

jobs:
lint:
Expand All @@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '15'
node-version: '16'
- run: npm ci
- run: npm run test-type-definitions
13 changes: 6 additions & 7 deletions lib/node-conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,22 @@ if (NodeReadableStream) {
async _read(size) {
try {
while (true) {
const { done, value } = await this._reader.read()
const { done, value } = await this._reader.read();
if (done) {
this.push(null);
break;
}
if (!this.push(value) || this._cancelling) {
this._reading = false;
if (!this.push(value)) {
break;
}
}
} catch(e) {
this.emit('error', e);
} catch (e) {
this.destroy(e);
}
}

_destroy(reason) {
this._reader.cancel(reason);
async _destroy(error, callback) {
this._reader.cancel(error).then(callback, callback);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Reader(input) {
const reader = input.getReader();
this._read = reader.read.bind(reader);
this._releaseLock = () => {};
this._cancel = () => {};
this._cancel = async () => {};
return;
}
let streamType = streams.isStream(input);
Expand Down
Loading

0 comments on commit 884ed5d

Please sign in to comment.