{"name":"fetch-blob","version":"3.2.0","description":"Blob & File implementation in Node.js, originally from node-fetch.","main":"index.js","type":"module","scripts":{"test":"node --experimental-loader ./test/http-loader.js ./test/test-wpt-in-node.js","report":"c8 --reporter json --reporter text npm run test","coverage":"npm run report && 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":{"@types/node":"^17.0.9","c8":"^7.11.0","typescript":"^4.5.4"},"funding":[{"type":"github","url":"https://github.com/sponsors/jimmywarting"},{"type":"paypal","url":"https://paypal.me/jimmywarting"}],"dependencies":{"node-domexception":"^1.0.0","web-streams-polyfill":"^3.0.3"},"types":"./index.d.ts","gitHead":"b8c8176ba48a2118c65c9d646089e7d9fa3cb8c2","_id":"fetch-blob@3.2.0","_nodeVersion":"18.3.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==","shasum":"f09b8d4bbd45adc6f0c20b7e787e793e309dcce9","tarball":"http://registry-npm.ywwl.com/fetch-blob/download/fetch-blob-3.2.0.tgz","fileCount":10,"unpackedSize":21755,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDudNvQVfDmUfiZpLK4mm/ygNwN9RdxPCaScl7kDlYZ8gIgclnWfUyRd+wv36Iu5Id93p+dWAnQC2zJKZbJgrw9/xA="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJixco7ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqghQ/+I2GOv0ckYVLM31o7fHYtNSAh3S8KPRA+aTP1yVxGzfwgHsaZ\r\nXeqq4UKbhA4oVacEYzAkL1YoxUx2Ys9+vRK1lzlbW1eyx6xurAct+XjerqmV\r\naNLtfSd6d6FUwSNtPvf1V3DV66fQbjDloOWjb0VRlUovADMkZ3YcLm+NL0Pk\r\nDhSbuMIEdymuecgmHw1ryAJYAzHi4gpjcAc8fqQ/PMabEIeM9+DMy4Jujh/X\r\nHJWXlo0O6sw6a4f4izTk6G8XDj1T+qR7Bzc7dOf1pezvFn3xTSANpDTt2PKU\r\nnnxGKUWY4wjoXCISZad1uBahFrhI8CM7yK+qS/N/x6EKdJMKM93qJI45IiEz\r\nLzYV+FXMBQYzyYMdtdWshVOCCyr3gew7qi0xGluQpj5WNx31qRs2gG8Mqux5\r\nME9cFJ4lRM6KZokdEazay2NA6kuo+Ps9BnofmPLbb4ZSQNR8z2c/du25YY3w\r\nbAyKenxEgfQwpZ3ZweAqO286OSzpPrKpKKDCEHBkZGUQSWoyPfWvUblF91b2\r\n3/Yx8u7RWREjzVUPzkfNSTGNdB+TrhW4Qk73fcunWcz3L14KuDQ9gyRT8Ykb\r\ndG9EFSsvp0uH8U9EDynxqC3A7Zh5t0fW5P9S3N0zYggc/RADiT3ATcIpKCPA\r\noV44Hl8Cqt3amuKma3aC8bVkXy09du9eoBI=\r\n=tXFl\r\n-----END PGP SIGNATURE-----\r\n","size":7689,"noattachment":false,"key":"/fetch-blob/-/fetch-blob-3.2.0.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.2.0_1657129530976_0.10045095451226915"},"_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":1657129531179,"_cnpm_publish_time":1657129531179,"dist-tags":{"latest":"4.0.0","RC":"3.0.0-rc.0"}}