{"name":"fetch-blob","version":"3.1.2","description":"Blob & File implementation in Node.js, originally from node-fetch.","main":"index.js","type":"module","scripts":{"lint":"xo test.js","test":"npm run lint && ava","report":"c8 --reporter json --reporter text ava","coverage":"c8 --reporter json --reporter text ava && 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","xo":{"rules":{"unicorn/prefer-node-protocol":"off","unicorn/numeric-separators-style":"off","unicorn/prefer-spread":"off","unicorn/prefer-number-properties":"off","import/extensions":["error","always",{"ignorePackages":true}]},"overrides":[{"files":"test.js","rules":{"node/no-unsupported-features/es-syntax":0,"node/no-unsupported-features/node-builtins":0}}]},"devDependencies":{"ava":"^3.15.0","c8":"^7.7.2","codecov":"^3.8.2","node-fetch":"^3.0.0-beta.9","typescript":"^4.3.2","xo":"^0.40.1"},"funding":[{"type":"github","url":"https://github.com/sponsors/jimmywarting"},{"type":"paypal","url":"https://paypal.me/jimmywarting"}],"dependencies":{"web-streams-polyfill":"^3.0.3"},"gitHead":"0b028432d0fd00841128a94817c2a81a9558463e","_id":"fetch-blob@3.1.2","_nodeVersion":"16.1.0","_npmVersion":"7.11.2","dist":{"integrity":"sha512-hunJbvy/6OLjCD0uuhLdp0mMPzP/yd2ssd1t2FCJsaA7wkWhpbp9xfuNVpv7Ll4jFhzp6T4LAupSiV9uOeg0VQ==","shasum":"6bc438675f3851ecea51758ac91f6a1cd1bacabd","tarball":"http://registry-npm.ywwl.com/fetch-blob/download/fetch-blob-3.1.2.tgz","fileCount":11,"unpackedSize":22612,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg8VisCRA9TVsSAnZWagAARbwP/2AcYR8wO4o0lJlh0vOU\nFgkC0xaDUHmTTLtMqaqRdpO5e7tq7/rzPlnb5aycsHKC4WdC/AXZU9LZdSPH\nOY+eEe2jBAh2wqUVtm6ELy5XKXQKUDBxztCHcT1/RB3Y0OiSyQ3/ceBjdPm+\n/ezKPW98x0cEF3NtVWC3i99vrmf7Gn9vWp+qOYyosOsKHJLGTlXDECh0IMgQ\n64gZlhimzSNA6m+6MoYdxzD+FYOyEsPTJ9zWEWaW45+dlzjJ1Mc6WBprpTfZ\nukmZ6AwV7N46lukgLNtbnI/MeucJqDKcZpW11Lx/4phNoy5hshWIGGEUU5AU\nQtDd3IomWevK4g4y/mbsubl/5DT0YoDSUoRf/HJIjRgH5vBppJPMrDdbAI0b\ntmFobu3y39oq1xVNaAcL3VYe642h1hHTtFk6Ewq8wpqgTmhANskep3nw6GWP\nb3Ds83t70xsFPF4x0fDpGhLkGyG2tZ8ilT2AR46SwwYrSdtZC1cZRhq/KRfN\nVXecjRIgwqwJRplHfqoP/0VCPBP95ilbJ6I3mdC7GYjTRsUWIpN34vEdnOat\nSDjvMSNpKRy+D80ZGOD2Pvt9m5jX/+0+vb003MVp408q9qguZR3VurD2Wymz\nbHvUAKCFy9yX5gAl+J9VQwimDsvwVEcJgU9+ezWY2BjOB8NINwBGMNO4m0yA\nfL53\r\n=pclR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB9EzgbE6sy1mmYqMjkOke/fp2DqBmeWNTCxJmVkwxAwAiEAyAbKKvd392Uc50Rqzqh16uboQUP7XuboTcJz3mg419Q="}],"size":8420,"noattachment":false,"key":"/fetch-blob/-/fetch-blob-3.1.2.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":"xxczaki@pm.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fetch-blob_3.1.2_1626429611917_0.45141052844757557"},"_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":1626429612061,"_cnpm_publish_time":1626429612061,"dist-tags":{"latest":"4.0.0","RC":"3.0.0-rc.0"}}