{"name":"fetch-blob","version":"3.1.3","description":"Blob & File implementation in Node.js, originally from node-fetch.","main":"index.js","type":"module","scripts":{"test-wpt":"node --experimental-loader ./test/http-loader.js ./test/test-wpt-in-node.js","test":"ava test.js","report":"c8 --reporter json --reporter text ava test.js","coverage":"c8 --reporter json --reporter text ava test.js && codecov -f coverage/coverage-final.json","prepublishOnly":"tsc --declaration --emitDeclarationOnly --allowJs index.js from.js"},"repository":{"type":"git","url":"git+https://github.com/node-fetch/fetch-blob.git"},"keywords":["blob","file","node-fetch"],"engines":{"node":"^12.20 || >= 14.13"},"author":{"name":"Jimmy Wärting","email":"jimmy@warting.se","url":"https://jimmy.warting.se"},"license":"MIT","bugs":{"url":"https://github.com/node-fetch/fetch-blob/issues"},"homepage":"https://github.com/node-fetch/fetch-blob#readme","devDependencies":{"ava":"^3.15.0","c8":"^7.7.2","codecov":"^3.8.2","node-fetch":"^3.0.0-beta.9","typescript":"^4.3.2"},"funding":[{"type":"github","url":"https://github.com/sponsors/jimmywarting"},{"type":"paypal","url":"https://paypal.me/jimmywarting"}],"dependencies":{"web-streams-polyfill":"^3.0.3"},"types":"./index.d.ts","gitHead":"8ab587d34080de94140b54f07168451e7d0b655e","_id":"fetch-blob@3.1.3","_nodeVersion":"17.0.1","_npmVersion":"8.1.0","dist":{"integrity":"sha512-ax1Y5I9w+9+JiM+wdHkhBoxew+zG4AJ2SvAD1v1szpddUIiPERVGBxrMcB2ZqW0Y3PP8bOWYv2zqQq1Jp2kqUQ==","shasum":"a7dca4855e39d3e3c5a1da62d4ee335c37d26012","tarball":"http://registry-npm.ywwl.com/fetch-blob/download/fetch-blob-3.1.3.tgz","fileCount":10,"unpackedSize":21679,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2q8PCRA9TVsSAnZWagAAvw8P/1dvURvPVzn7TYtI9Yqv\nssj05vt6pYZjc+Y4RETvQAO1JxmXTzLwPPfwm7B/JrggXKaW96j3cPDbB4UN\n0ShNIorWj6fg/Zt6mN20QcTw7znH/EvWtmYLC+89l0TbTx6G8ldnCA4wXWI/\n3NrlDOm2coTep3jhvXWJBoCuAdYFJPdJrYxvZgF3/uWBwkWJs3H4Fj7hSmRV\nxBGjVhZAEAr2TQ3FFnXKER+Thz7kK0YBu6GqJ27hA4mvQUCHRhKfXvaiAPOl\nlvu+JNJDgn6F7k3xIeUEosXnPEYWZAfX2T3zYxY/3xhX+ouA+wq8GIMo94g1\nDUmgP64aFZ+uj7oz05Syo/Gn2OnNrcLa+kBo/KG2PeGqKseDGYXEx0+opN0p\nFRb/u6daI62BzNd8iRNltrAuOTV1oSRybSGqMIhEmJGpUbo+6SF+bnpd+isV\nTiwy3rTo+zUwdv7W2d87QjWLwhhG+Hu6XCPqd0XR7XPVxTZ0vNenPMgUD51K\npvqgrPvK7dHe6y/XBEX5ZzNFSaErp3zL0u1Ud+R6O7LD2uOPwksEV6D+tAEB\n6yn1xQsRJaNEt5jz8j58JSY3lSW1MDz1aT2WgrczACJ1onYFA6j77VuELtBi\nlAgDQtRtkwCdWWdpAct+cV63Un1wuhR9Ru8LXDoESfWqlfVNsP/0MsiYk3IZ\nCrLr\r\n=LGyG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC1VKims7evo28l5ynnI2i4j14mzyD0sVmuUHl3NqWOiwIgEnROsfiG1hnnBO1QTuTk3eE67Tn8YaIvEptUKpK/jO4="}],"size":7682,"noattachment":false,"key":"/fetch-blob/-/fetch-blob-3.1.3.tgz"},"_npmUser":{"name":"endless","email":"jimmy@warting.se"},"directories":{},"maintainers":[{"name":"endless","email":"jimmy@warting.se"},{"name":"bitinn","email":"bitinn@gmail.com"},{"name":"akepinski","email":"npm@kepinski.ch"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fetch-blob_3.1.3_1635596396065_0.5964602541736606"},"_hasShrinkwrap":false,"readme":"# fetch-blob\n\n[![npm version][npm-image]][npm-url]\n[![build status][ci-image]][ci-url]\n[![coverage status][codecov-image]][codecov-url]\n[![install size][install-size-image]][install-size-url]\n\nA Blob implementation in Node.js, originally from [node-fetch](https://github.com/node-fetch/node-fetch).\n\nUse the built-in [`Blob`](https://nodejs.org/docs/latest-v18.x/api/buffer.html#class-blob) in Node.js 18 and later.\n\n## Installation\n\n```sh\nnpm install fetch-blob\n```\n\n<details>\n  <summary>Upgrading from 2x to 3x</summary>\n\n  Updating from 2 to 3 should be a breeze since there is not many changes to the blob specification.\n  The major cause of a major release is coding standards.\n    - internal WeakMaps was replaced with private fields\n    - internal Buffer.from was replaced with TextEncoder/Decoder\n    - internal buffers was replaced with Uint8Arrays\n    - CommonJS was replaced with ESM\n    - The node stream returned by calling `blob.stream()` was replaced with whatwg streams\n    - (Read \"Differences from other blobs\" for more info.)\n</details>\n\n<details>\n  <summary>Differences from other Blobs</summary>\n\n  - Unlike NodeJS `buffer.Blob` (Added in: v15.7.0) and browser native Blob this polyfilled version can't be sent via PostMessage\n  - This blob version is more arbitrary, it can be constructed with blob parts that isn't a instance of itself\n  it has to look and behave as a blob to be accepted as a blob part.\n    - The benefit of this is that you can create other types of blobs that don't contain any internal data that has to be read in other ways, such as the `BlobDataItem` created in `from.js` that wraps a file path into a blob-like item and read lazily (nodejs plans to [implement this][fs-blobs] as well)\n  - The `blob.stream()` is the most noticeable differences. It returns a WHATWG stream now. to keep it as a node stream you would have to do:\n\n  ```js\n    import {Readable} from 'stream'\n    const stream = Readable.from(blob.stream())\n  ```\n</details>\n\n## Usage\n\n```js\n// Ways to import\nimport { Blob } from 'fetch-blob'\nimport { File } from 'fetch-blob/file.js'\n\nconst { Blob } = await import('fetch-blob')\n\n\n// Ways to read the blob:\nconst blob = new Blob(['hello, world'])\n\nawait blob.text()\nawait blob.arrayBuffer()\nfor await (let chunk of  blob.stream()) { ... }\nblob.stream().getReader().read()\nblob.stream().getReader({mode: 'byob'}).read(view)\n```\n\n### Blob part backed up by filesystem\n\n`fetch-blob/from.js` comes packed with tools to convert any filepath into either a Blob or a File\nIt will not read the content into memory. It will only stat the file for last modified date and file size.\n\n```js\n// The default export is sync and use fs.stat to retrieve size & last modified as a blob\nimport {File, Blob, blobFrom, blobFromSync, fileFrom, fileFromSync} from 'fetch-blob/from.js'\n\nconst fsFile = fileFromSync('./2-GiB-file.bin', 'application/octet-stream')\nconst fsBlob = await blobFrom('./2-GiB-file.mp4')\n\n// Not a 4 GiB memory snapshot, just holds references\n// points to where data is located on the disk\nconst blob = new Blob([fsFile, fsBlob, 'memory', new Uint8Array(10)])\nconsole.log(blob.size) // ~4 GiB\n```\n\n`blobFrom|blobFromSync|fileFrom|fileFromSync(path, [mimetype])`\n\n### Creating a temporary file on the disk\n(requires [FinalizationRegistry] - node v14.6)\n\nWhen using both `createTemporaryBlob` and `createTemporaryFile`\nthen you will write data to the temporary folder in their respective OS.\nThe arguments can be anything that [fsPromises.writeFile] supports. NodeJS\nv14.17.0+ also supports writing (async)Iterable streams and passing in a\nAbortSignal, so both NodeJS stream and whatwg streams are supported. When the\nfile have been written it will return a Blob/File handle with a references to\nthis temporary location on the disk. When you no longer have a references to\nthis Blob/File anymore and it have been GC then it will automatically be deleted.\n\nThis files are also unlinked upon exiting the process.\n```js\nimport { createTemporaryBlob, createTemporaryFile } from 'fetch-blob/from.js'\n\nconst req = new Request('https://httpbin.org/image/png')\nconst res = await fetch(req)\nconst type = res.headers.get('content-type')\nconst signal = req.signal\nlet blob = await createTemporaryBlob(res.body, { type, signal })\n// const file = createTemporaryBlob(res.body, 'img.png', { type, signal })\nblob = undefined // loosing references will delete the file from disk\n```\n\n- `createTemporaryBlob(data, { type, signal })`\n- `createTemporaryFile(data, FileName, { type, signal, lastModified })`\n\n### Creating Blobs backed up by other async sources\nOur Blob & File class are more generic then any other polyfills in the way that it can accept any blob look-a-like item\nAn example of this is that our blob implementation can be constructed with parts coming from [BlobDataItem](https://github.com/node-fetch/fetch-blob/blob/8ef89adad40d255a3bbd55cf38b88597c1cd5480/from.js#L32) (aka a filepath) or from [buffer.Blob](https://nodejs.org/api/buffer.html#buffer_new_buffer_blob_sources_options), It dose not have to implement all the methods - just enough that it can be read/understood by our Blob implementation. The minium requirements is that it has `Symbol.toStringTag`, `size`, `slice()`, `stream()` methods (the stream method\ncan be as simple as being a sync or async iterator that yields Uint8Arrays. If you then wrap it in our Blob or File `new Blob([blobDataItem])` then you get all of the other methods that should be implemented in a blob or file (aka: text(), arrayBuffer() and type and a ReadableStream)\n\nAn example of this could be to create a file or blob like item coming from a remote HTTP request. Or from a DataBase\n\nSee the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and [tests](https://github.com/node-fetch/fetch-blob/blob/master/test.js) for more details of how to use the Blob.\n\n[npm-image]: https://flat.badgen.net/npm/v/fetch-blob\n[npm-url]: https://www.npmjs.com/package/fetch-blob\n[ci-image]: https://github.com/node-fetch/fetch-blob/workflows/CI/badge.svg\n[ci-url]: https://github.com/node-fetch/fetch-blob/actions\n[codecov-image]: https://flat.badgen.net/codecov/c/github/node-fetch/fetch-blob/master\n[codecov-url]: https://codecov.io/gh/node-fetch/fetch-blob\n[install-size-image]: https://flat.badgen.net/packagephobia/install/fetch-blob\n[install-size-url]: https://packagephobia.now.sh/result?p=fetch-blob\n[fs-blobs]: https://github.com/nodejs/node/issues/37340\n[fsPromises.writeFile]: https://nodejs.org/dist/latest-v18.x/docs/api/fs.html#fspromiseswritefilefile-data-options\n[FinalizationRegistry]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry\n","publish_time":1635596396214,"_cnpm_publish_time":1635596396214,"dist-tags":{"latest":"4.0.0","RC":"3.0.0-rc.0"}}