{"name":"fetch-blob","version":"3.1.5","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":"d4632ad83e399f2b259a2a57b3f01be8bcbe7d1d","_id":"fetch-blob@3.1.5","_nodeVersion":"17.4.0","_npmVersion":"8.3.1","dist":{"integrity":"sha512-N64ZpKqoLejlrwkIAnb9iLSA3Vx/kjgzpcDhygcqJ2KKjky8nCgUQ+dzXtbrLaWZGZNmNfQTsiQ0weZ1svglHg==","shasum":"0077bf5f3fcdbd9d75a0b5362f77dbb743489863","tarball":"http://registry-npm.ywwl.com/fetch-blob/download/fetch-blob-3.1.5.tgz","fileCount":10,"unpackedSize":22063,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiMRgUACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq8+w/9ErDOi3NPC0SQHjd7hVlN46Ny/i7OPR9BUZgzgSsY90jKlA1u\r\nCqXlYRbxlEWomrUc6imhq7/Nmlyg20DAFwCBAE5LZhzZQkXrH8Zopd2zGHpd\r\nEos3ny3Tf7GOcJvecyYkh+2AqYeGxgwBQG8pM0VXQCtxR3BvqJ95352ZPD7m\r\nPK7gYGtJQU87lL872Kz8A+NQRmSNs93/pXfvc2vh/W8acGEqs1lWH/++smZB\r\nJ7LQCza+rJ/qUoQ9yesgsD70aTbBj9aGjZTpbA/jmnk4EopCBYR93/vzUHMZ\r\nY4Dbq5vTV6E286K8MAvKjSv2pcrN7+pGxoIv8KODRQgvS+oo6tTDUdszi1GR\r\nBPO3fBvZFIB3vvnLrf4ciDs/RTL5B0mOmAqQA4Mdi/blGBuWifhHAYpSt84a\r\nsf4d1VIzalCnCS3NXjApZkLHO8KBoLc8CQj8FXLksTT4zEk6HwaJak5ut3CU\r\nWYIu7XNiWh7X1Lt2Lvvwqi4n0qu1U05Hns1mDxzDxm8n/PH4I+6BYan1VTgz\r\nB0oudN/IkmnAIEBvw9XYl0xr6RVM4of54DMXrJAOATjzn1Frp21mkYPzNhxo\r\ndP9/p/wqEsxJ/rg/W7OQzSWKjtEm/5hs/YyI0w/miWbfMTskmzA3bjHESpKq\r\nH+aJ2ZYAbLMStBOTVe3z1ELBfq2/Z8DAPYU=\r\n=BIAx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCn/FZ6M0r96/WtHQ0Eb1AzkILuPj0+uoILdqEaZyVZEwIgcmH2kZ133Ujr20NQjcqsjc7/fbIkf16+HamXBsZMIkA="}],"size":7770,"noattachment":false,"key":"/fetch-blob/-/fetch-blob-3.1.5.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.5_1647384596212_0.9138752697477188"},"_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":1647384596424,"_cnpm_publish_time":1647384596424,"dist-tags":{"latest":"4.0.0","RC":"3.0.0-rc.0"}}