readable-web-to-node-stream
Advanced tools
Comparing version 1.0.0 to 1.1.0
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -37,21 +29,20 @@ const initDebug = require("debug"); | ||
*/ | ||
_read() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// Should start pushing data into the queue | ||
// Read data from the underlying Web-API-readable-stream | ||
if (this.released) { | ||
return; | ||
} | ||
this.pendingRead = this.reader.read(); | ||
const data = yield this.pendingRead; | ||
// clear the promise before pushing pushing new data to the queue and allow sequential calls to _read() | ||
delete this.pendingRead; | ||
if (data.done || this.released) { | ||
this.push(null); // Signal EOF | ||
} | ||
else { | ||
this.bytesRead += data.value.length; | ||
this.push(data.value); // Push new data to the queue | ||
} | ||
}); | ||
async _read() { | ||
// Should start pushing data into the queue | ||
// Read data from the underlying Web-API-readable-stream | ||
if (this.released) { | ||
this.push(null); // Signal EOF | ||
return; | ||
} | ||
this.pendingRead = this.reader.read(); | ||
const data = await this.pendingRead; | ||
// clear the promise before pushing pushing new data to the queue and allow sequential calls to _read() | ||
delete this.pendingRead; | ||
if (data.done || this.released) { | ||
this.push(null); // Signal EOF | ||
} | ||
else { | ||
this.bytesRead += data.value.length; | ||
this.push(data.value); // Push new data to the queue | ||
} | ||
} | ||
@@ -62,8 +53,6 @@ /** | ||
*/ | ||
waitForReadToComplete() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.pendingRead) { | ||
yield this.pendingRead; | ||
} | ||
}); | ||
async waitForReadToComplete() { | ||
if (this.pendingRead) { | ||
await this.pendingRead; | ||
} | ||
} | ||
@@ -73,17 +62,13 @@ /** | ||
*/ | ||
close() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
debug(`close()`); | ||
yield this.syncAndRelease(); | ||
}); | ||
async close() { | ||
debug(`close()`); | ||
await this.syncAndRelease(); | ||
} | ||
syncAndRelease() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
debug(`syncAndRelease()`); | ||
this.released = true; | ||
yield this.waitForReadToComplete(); | ||
yield this.reader.releaseLock(); | ||
}); | ||
async syncAndRelease() { | ||
debug(`syncAndRelease()`); | ||
this.released = true; | ||
await this.waitForReadToComplete(); | ||
await this.reader.releaseLock(); | ||
} | ||
} | ||
exports.ReadableWeToNodeStream = ReadableWeToNodeStream; |
{ | ||
"name": "readable-web-to-node-stream", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Converts a Web-API readable-stream into a Node readable-stream.", | ||
@@ -15,2 +15,3 @@ "main": "dist/index.js", | ||
"lint": "npm run tslint && npm run eslint", | ||
"test": "karma start --single-run", | ||
"karma": "karma start", | ||
@@ -30,3 +31,4 @@ "karma-firefox": "karma start --browsers Firefox", | ||
"coverter", | ||
"readable" | ||
"readable", | ||
"readablestream" | ||
], | ||
@@ -33,0 +35,0 @@ "repository": "https://github.com/Borewit/readable-web-to-node-stream.git", |
[![Build Status](https://travis-ci.org/Borewit/readable-web-to-node-stream.svg?branch=master)](https://travis-ci.org/Borewit/readable-web-to-node-stream) | ||
[![NPM version](https://badge.fury.io/js/readable-web-to-node-stream.svg)](https://npmjs.org/package/readable-web-to-node-stream) | ||
[![npm downloads](http://img.shields.io/npm/dm/readable-web-to-node-stream.svg)](https://npmjs.org/package/readable-web-to-node-stream) | ||
[![npm downloads](http://img.shields.io/npm/dm/readable-web-to-node-stream.svg)](https://npmcharts.com/compare/readable-web-to-node-stream) | ||
[![dependencies Status](https://david-dm.org/Borewit/readable-web-to-node-stream/status.svg)](https://david-dm.org/Borewit/readable-web-to-node-stream) | ||
@@ -10,3 +10,2 @@ [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/readable-web-to-node-stream/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/readable-web-to-node-stream?targetFile=package.json) | ||
# readable-web-stream-to-node | ||
@@ -16,3 +15,3 @@ | ||
### Installation | ||
## Installation | ||
Install via [npm](http://npmjs.org/): | ||
@@ -28,2 +27,13 @@ | ||
## Compatibility | ||
Source is written in TypeScript and compiled to ECMAScript 2017 (ES8). | ||
Unit tests are performed on the following browsers: | ||
* Google Chrome 74.0 | ||
* Firefox 68.0 | ||
* Safari 12.0 | ||
* Opera 60.0 | ||
## Examples | ||
@@ -30,0 +40,0 @@ |
@@ -10,3 +10,3 @@ { | ||
"experimentalDecorators": true, | ||
"target": "es6", | ||
"target": "ES2017", | ||
"typeRoots": [ | ||
@@ -13,0 +13,0 @@ "node_modules/@types" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87
15689
264