{"_id":"fetch-readablestream","_rev":"6-3b3fbe5c1758ace7ee855f75fb43f300","name":"fetch-readablestream","description":"Compatibility layer for efficient streaming of binary data using [WHATWG Streams](https://streams.spec.whatwg.org/)","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"fetch-readablestream","version":"0.1.0","main":"lib/entry.js","jsnext:main":"src/index.js","repository":{"type":"git","url":"git+https://github.com/jonnyreeves/fetch-readablestream.git"},"license":"MIT","keywords":["xhr","fetch","polyfill","readablestream"],"scripts":{"prepublish":"npm run clean && npm run build:lib && ./post-build.sh","clean":"rm -rf build/* && rm -rf dist/*","build:integ":"mkdir -p build && $BROWSERIFY_CMD test/integ/*.spec.js -o build/integration-tests.js --debug -t [ babelify ]","build:lib":"mkdir -p lib && babel --out-dir lib src","lint":"eslint .","test":"npm run lint && npm run test:integ","test:integ":"BROWSERIFY_CMD=browserify npm run build:integ && ./run-karma.sh --single-run","watch":"(BROWSERIFY_CMD=watchify npm run build:integ &) && ./run-karma.sh --auto-watch","release":"./release.sh ${npm_package_version}"},"devDependencies":{"babel-cli":"^6.11.4","babel-polyfill":"^6.13.0","babel-preset-es2015":"^6.13.2","babelify":"^7.3.0","browserify":"^13.1.0","cookie":"^0.3.1","eslint":"^3.3.1","jasmine":"^2.4.1","jasmine-core":"^2.4.1","karma":"^1.2.0","karma-jasmine":"^1.0.2","karma-sauce-launcher":"^1.0.0","text-encoding":"^0.6.0","url":"^0.11.0","watchify":"^3.7.0","web-streams-polyfill":"^1.3.0"},"gitHead":"ee7862184add68d3ba8f56a18ac6b432c4be05e6","description":"Compatibility layer for efficient streaming of binary data using [WHATWG Streams](https://streams.spec.whatwg.org/)","bugs":{"url":"https://github.com/jonnyreeves/fetch-readablestream/issues"},"homepage":"https://github.com/jonnyreeves/fetch-readablestream#readme","_id":"fetch-readablestream@0.1.0","_shasum":"2219bccea9bf3b97cb599624094099eafaa400be","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"jonnyreeves","email":"npm@jonnyreeves.co.uk"},"dist":{"shasum":"2219bccea9bf3b97cb599624094099eafaa400be","tarball":"https://registry.npmjs.org/fetch-readablestream/-/fetch-readablestream-0.1.0.tgz","integrity":"sha512-Cs0CV+54nipyMXmLQ/dcN6oh2D6XEuRS3t3iSrfhzzil0QooTIfBM1/OmLe5uViSplS15lgeL2oT9iGZCZiTow==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEtNiD86KYS2r6vkZXsHw7h70qhqcDUbhh4F4tJOT/jwAiEAsWnsBFOvV8tdGJq1+pVR25x5hfxRz1fxQ+FoLv9v8nk="}]},"maintainers":[{"name":"jonnyreeves","email":"npm@jonnyreeves.co.uk"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/fetch-readablestream-0.1.0.tgz_1474471831305_0.2789325388148427"},"directories":{}},"0.2.0":{"name":"fetch-readablestream","version":"0.2.0","main":"lib/entry.js","jsnext:main":"src/index.js","repository":{"type":"git","url":"git+https://github.com/jonnyreeves/fetch-readablestream.git"},"license":"MIT","keywords":["xhr","fetch","polyfill","readablestream"],"scripts":{"prepare":"npm run clean && npm run build:lib && ./post-build.sh","clean":"rm -rf build/* && rm -rf dist/*","build:integ":"mkdir -p build && $BROWSERIFY_CMD test/integ/*.spec.js -o build/integration-tests.js --debug -t [ babelify ]","build:lib":"mkdir -p lib && babel --out-dir lib src","lint":"eslint .","test":"npm run lint && npm run test:integ","test:integ":"BROWSERIFY_CMD=browserify npm run build:integ && ./run-karma.sh --single-run","watch":"(BROWSERIFY_CMD=watchify npm run build:integ &) && ./run-karma.sh --auto-watch","release":"./release.sh ${npm_package_version}"},"devDependencies":{"abortcontroller-polyfill":"^1.1.9","babel-cli":"^6.11.4","babel-polyfill":"^6.13.0","babel-preset-es2015":"^6.13.2","babelify":"^7.3.0","browserify":"^13.1.0","cookie":"^0.3.1","eslint":"^3.3.1","jasmine":"^2.4.1","jasmine-core":"^2.4.1","karma":"^1.7.1","karma-jasmine":"^1.1.2","karma-sauce-launcher":"^1.2.0","text-encoding":"^0.6.0","url":"^0.11.0","watchify":"^3.7.0","web-streams-polyfill":"^1.3.0"},"gitHead":"10198c943d04789b0f7d15c72bbf2868a40213ea","description":"Compatibility layer for efficient streaming of binary data using [WHATWG Streams](https://streams.spec.whatwg.org/)","bugs":{"url":"https://github.com/jonnyreeves/fetch-readablestream/issues"},"homepage":"https://github.com/jonnyreeves/fetch-readablestream#readme","_id":"fetch-readablestream@0.2.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"jonnyreeves","email":"npm@jonnyreeves.co.uk"},"dist":{"integrity":"sha512-qu4mXWf4wus4idBIN/kVH+XSer8IZ9CwHP+Pd7DL7TuKNC1hP7ykon4kkBjwJF3EMX2WsFp4hH7gU7CyL7ucXw==","shasum":"eaa6d1a76b12de2d4731a343393c6ccdcfe2c795","tarball":"https://registry.npmjs.org/fetch-readablestream/-/fetch-readablestream-0.2.0.tgz","fileCount":18,"unpackedSize":38971,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb5KIfCRA9TVsSAnZWagAAGVgP/18Khz4aJMrTYnp3aboI\ntOqVo9sFwgg+Gl6MJhkl1d6ibJEZDq0I4WSzDEo3yhtszgibwXLIWfoFoKdw\ncIjfckPLcmSzOvFPpzyYzyCvRaiRLL9Ux62y66SaKk6YM6AxD85drpON0AFy\n3L3ziAl4gUiRt6VWyZnyfa6mbhpe0SNWZbcD3tXzVbztRrrnUCmL1lGecNGF\nOGJToxJadZX3e4/0hHllJJ5SqoYN2IDm4rv88z4i1F0xspNt0iT7e7iHqBqc\nl98v36eSpIJHIIiWnQLtXJBR4qs3DjApTxtI4Mr4yVj4PO+5r7Boa1bD6sgG\nyiuOxl0JdmBoVlF3HV9LPurBHPz2RI3oKvyOcJObi/2zu2OTeZE8V+9pptnC\nRw02vpbr+smLWwUvGBkAR+q+79HrpBPIJvkviaTAAlZ1KgkKXcmZ8uP30kTI\noFjniqQN0Ya+Od2jJSxyGUBZ2qZGaL+X8PoYgi7vN8kPbJsgJP+yga0r9aXq\nNfEdk0yCodRW3uVRZN9kDjuAE364VgAm2X5Ca42SypGIHMWZEccxCuyq2PO6\nAkgvKyM7u19/yWiO+sNI+dQBd8hOAAHP8pL2B2e1RsnSkipmOiJjFQPE1HzN\ns1VQ/SDM3O8nvGihhXO8IRwAJYxNYPHocYEFA/4Q28XoszUzDsEBoc6Gt+mq\nBNYt\r\n=tFHO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCZr8MsNoJXcwlisSpbiu88/x1+KE73mEQs2QzTxfXZHAIgA6a7sV/kLmtA7SOG9XIprR7b3dg3+DlT+aTfV07/+30="}]},"maintainers":[{"name":"jonnyreeves","email":"npm@jonnyreeves.co.uk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fetch-readablestream_0.2.0_1541710366391_0.44726251246525783"},"_hasShrinkwrap":false}},"readme":"# fetch-readablestream\nCompatibility layer for efficient streaming of binary data using [WHATWG Streams](https://streams.spec.whatwg.org/)\n\n## Why\nThis library provides a consistent, cross browser API for streaming a response from an HTTP server based on the [WHATWG Streams specification](https://streams.spec.whatwg.org/).  At the time of writing, Chrome is the only browser to nativley support returning a `ReadableStream` from it's `fetch` implementation - all other browsers need to fall back to `XMLHttpRequest`.\n\nFireFox does provide the ability to efficiently retrieve a byte-stream from a server; however only via it's `XMLHttpRequest` implementation (when using `responsetype=moz-chunked-arraybuffer`).  Other browsers do not provide access to the underlying byte-stream and must therefore fall-back to concatenating the response string and then encoding it into it's UTF-8 byte representation using the [`TextEncoder` API](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder).\n\n*Nb:* If you are happy using a node-style API (using callbacks and events) I would suggest taking a look at [`stream-http`](https://github.com/jhiesey/stream-http).\n\n## Installation\nThis package can be installed with `npm`:\n\n```\n$ npm install fetch-readablestream --save\n```\n\nOnce installed you can import it directly:\n\n```js\nimport fetchStream from 'fetch-readablestream';\n```\n\nOr you can add a script tag pointing to the `dist/fetch-readablestream.js` bundle and use the `fetchStream` global:\n\n```html\n<script src=\"./node_modules/fetch-readablestream/dist/fetch-readablestream.js\"></script>\n<script>\n  window.fetchStream('...')\n</script>\n```\n\n## Usage\nThe `fetchStream` api provides a subset of the [`fetch` API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch); in particular, the ability to get a `ReadableStream` back from the `Response` object which can be used to efficiently stream a chunked-transfer encoded response from the server.\n\n```js\nfunction readAllChunks(readableStream) {\n  const reader = readableStream.getReader();\n  const chunks = [];\n\n  function pump() {\n    return reader.read().then(({ value, done }) => {\n      if (done) {\n        return chunks;\n      }\n      chunks.push(value);\n      return pump();\n    });\n  }\n\n  return pump();\n}\n\nfetchStream('/endpoint')\n  .then(response => readAllChunks(response.body))\n  .then(chunks => console.dir(chunks))\n```\n\n`AbortController` is supported [in many environments](https://caniuse.com/#feat=abortcontroller), and allows you to abort ongoing requests. This is fully supported in any environment that supports both ReadableStreams & AbortController directly (e.g. Chrome 66+), and has basic support in most other environments, though you may need [a polyfill](https://www.npmjs.com/package/abortcontroller-polyfill) in your own code to use it. To abort a request:\n\n```js\nconst controller = new AbortController();\n\nfetchStream('/endpoint', {\n  signal: controller.signal\n}).then(() => {\n  // ...\n});\n\n// To abort the ongoing request:\ncontroller.abort();\n```\n\n## Browser Compatibility\n`fetch-readablestream` makes the following assumptions on the environment; legacy browsers will need to provide Polyfills for this functionality:\n\n| Feature                        | Browsers                         | Polyfill |\n|--------------------------------|----------------------------------|----------|\n| ReadableStream                 | Firefox, Safari, IE11, PhantomJS | [web-streams-polyfill](https://www.npmjs.com/package/web-streams-polyfill) |\n| TextEncoder                    | Safari, IE11, PhantomJS          | [text-encoding](https://www.npmjs.com/package/text-encoding) |\n| Promise, Symbol, Object.assign | IE11, PhantomJS                  | [babel-polyfill](https://www.npmjs.com/package/babel-polyfill) |\n\n## Contributing\nUse `npm run watch` to fire up karma with live-reloading.  Visit http://localhost:9876/ in a bunch of browsers to capture them - the test suite will run automatically and report any failures.\n\n\n","maintainers":[{"name":"jonnyreeves","email":"npm@jonnyreeves.co.uk"}],"time":{"modified":"2022-06-18T00:16:47.285Z","created":"2016-09-21T15:30:33.792Z","0.1.0":"2016-09-21T15:30:33.792Z","0.2.0":"2018-11-08T20:52:46.574Z"},"homepage":"https://github.com/jonnyreeves/fetch-readablestream#readme","keywords":["xhr","fetch","polyfill","readablestream"],"repository":{"type":"git","url":"git+https://github.com/jonnyreeves/fetch-readablestream.git"},"bugs":{"url":"https://github.com/jonnyreeves/fetch-readablestream/issues"},"license":"MIT","readmeFilename":"README.md","users":{"usex":true}}