From 8658816b904565ad5b85ac7d9baaf8faabe488be Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Thu, 17 May 2018 19:43:20 +0200 Subject: [PATCH] Add Web Streams polyfill --- package.json | 3 ++- src/stream.js | 4 ++++ test/unittests.js | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d0f8f524..cb62bfbc 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,8 @@ "node-fetch": "^2.1.2", "node-localstorage": "~1.3.0", "pako": "^1.0.6", - "rusha": "^0.8.12" + "rusha": "^0.8.12", + "web-streams-polyfill": "^1.3.2" }, "repository": { "type": "git", diff --git a/src/stream.js b/src/stream.js index 7eaafebf..2a0046f3 100644 --- a/src/stream.js +++ b/src/stream.js @@ -1,5 +1,9 @@ import util from './util'; +if (typeof ReadableStream === 'undefined') { + Object.assign(typeof window !== 'undefined' ? window : global, require('web-streams-polyfill')); +} + function concat(arrays) { const readers = arrays.map(getReader); let current = 0; diff --git a/test/unittests.js b/test/unittests.js index f25c0998..fc1524fd 100644 --- a/test/unittests.js +++ b/test/unittests.js @@ -5,6 +5,9 @@ if (typeof Symbol === 'undefined') { if (typeof Promise === 'undefined') { require('core-js/fn/promise'); } +if (typeof ReadableStream === 'undefined') { + Object.assign(typeof window !== 'undefined' ? window : global, require('web-streams-polyfill')); +} (typeof window !== 'undefined' ? window : global).resolves = function(val) { return new Promise(function(res) { res(val); });