Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c54489a35 | ||
|
|
b76652eaaf | ||
|
|
f23cdad2a8 | ||
|
|
40e6f7ea13 | ||
|
|
aef02263c1 | ||
|
|
4dc9ba543f | ||
|
|
1a29178875 | ||
|
|
c87ebb6711 | ||
|
|
b363c0fa81 | ||
|
|
eb1d304ede | ||
|
|
9ebbbe6553 | ||
|
|
a1a182e597 | ||
|
|
57e4daef36 | ||
|
|
0455796ede | ||
|
|
2acec9c0dc | ||
|
|
20ee08f33e |
@@ -12,9 +12,8 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------
|
||||
|
||||
<!-- Mark what you have done, Remove unnecessary ones. Add new tasks that may fit (like TODO's) -->
|
||||
<!-- Mark what you have done with [x], Remove unnecessary ones. Add new tasks that may fit (like TODO's) -->
|
||||
- [ ] I prefixed the PR-title with `docs: `, `fix(area): `, `feat(area): ` or `breaking(area): `
|
||||
- [ ] I updated ./CHANGELOG.md with a link to this PR or Issue
|
||||
- [ ] I updated the README.md
|
||||
- [ ] I Added unit test(s)
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
node: ["17.3"]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
node: ["18", "20", "22"]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
@@ -22,10 +22,12 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '17.3'
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
- run: npm run report -- --colors
|
||||
node-version: ${{ matrix.node }}
|
||||
- run: corepack enable
|
||||
- run: corepack prepare pnpm@latest --activate
|
||||
- run: pnpm install
|
||||
- run: pnpm test
|
||||
- run: pnpm run report -- --colors
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"cSpell.words": ["Wärting"]
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
|
||||
project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## v3.1.3
|
||||
- Allow usage of iterable object in Blob constructor. [#108]
|
||||
- Run test WPT test against our impl [#109]
|
||||
- File name are now casted to string [#109]
|
||||
- Slicing in the middle of multiple parts added more bytes than what what it should have [#109]
|
||||
- Prefixed `stream/web` import with `node:` to allow easier static analysis detection of Node built-ins [#122]
|
||||
- Added `node:` prefix in `from.js` as well [#114]
|
||||
- Suppress warning when importing `stream/web` [#114]
|
||||
|
||||
## v3.1.2
|
||||
- Improved typing
|
||||
- Fixed a bug where position in iterator did not increase
|
||||
|
||||
## v3.1.0
|
||||
- started to use real whatwg streams
|
||||
- degraded fs/promise to fs.promise to support node v12
|
||||
- degraded optional changing to support node v12
|
||||
|
||||
## v3.0.0
|
||||
- Changed WeakMap for private field (require node 12)
|
||||
- Switch to ESM
|
||||
- blob.stream() return a subset of whatwg stream which is the async iterable part
|
||||
(it no longer return a node stream)
|
||||
- Reduced the dependency of Buffer by changing to global TextEncoder/Decoder (require node 11)
|
||||
- Disabled xo since it could understand private fields (#)
|
||||
- No longer transform the type to lowercase (https://github.com/w3c/FileAPI/issues/43)
|
||||
This is more loose than strict, keys should be lowercased, but values should not.
|
||||
It would require a more proper mime type parser - so we just made it loose.
|
||||
- index.js and file.js can now be imported by browser & deno since it no longer depends on any
|
||||
core node features (but why would you?)
|
||||
- Implemented a File class
|
||||
|
||||
## v2.1.2
|
||||
- Fixed a bug where `start` in BlobDataItem was undefined (#85)
|
||||
|
||||
## v2.1.1
|
||||
- Add nullish values checking in Symbol.hasInstance (#82)
|
||||
- Add generated typings for from.js file (#80)
|
||||
- Updated dev dependencies
|
||||
|
||||
## v2.1.0
|
||||
- Fix: .slice has an implementation bug (#54).
|
||||
- Added blob backed up by filesystem (#55)
|
||||
|
||||
## v2.0.1
|
||||
|
||||
- Fix: remove upper bound for node engine semver (#49).
|
||||
|
||||
## v2.0.0
|
||||
|
||||
> Note: This release was previously published as `1.0.7`, but as it contains breaking changes, we renamed it to `2.0.0`.
|
||||
|
||||
- **Breaking:** minimum supported Node.js version is now 10.17.
|
||||
- **Breaking:** `buffer` option has been removed.
|
||||
- Enhance: create TypeScript declarations from JSDoc (#45).
|
||||
- Enhance: operate on blob parts (byte sequence) (#44).
|
||||
- Enhance: use a `WeakMap` for private properties (#42) .
|
||||
- Other: update formatting.
|
||||
|
||||
## v1.0.6
|
||||
|
||||
- Enhance: use upstream Blob directly in typings (#38)
|
||||
- Other: update dependencies
|
||||
|
||||
## v1.0.5
|
||||
|
||||
- Other: no change to code, update dev dependency to address vulnerability reports
|
||||
|
||||
## v1.0.4
|
||||
|
||||
- Other: general code rewrite to pass linting, prepare for `node-fetch` release v3
|
||||
|
||||
## v1.0.3
|
||||
|
||||
- Fix: package.json export `blob.js` properly now
|
||||
|
||||
## v1.0.2
|
||||
|
||||
- Other: fix test integration
|
||||
|
||||
## v1.0.1
|
||||
|
||||
- Other: readme update
|
||||
|
||||
## v1.0.0
|
||||
|
||||
- Major: initial release
|
||||
|
||||
[#108]: https://github.com/node-fetch/fetch-blob/pull/108
|
||||
[#109]: https://github.com/node-fetch/fetch-blob/pull/109
|
||||
[#114]: https://github.com/node-fetch/fetch-blob/pull/114
|
||||
@@ -1,32 +1,26 @@
|
||||
# fetch-blob
|
||||
# fetch-blob-fixed
|
||||
|
||||
[![npm version][npm-image]][npm-url]
|
||||
[![build status][ci-image]][ci-url]
|
||||
[![coverage status][codecov-image]][codecov-url]
|
||||
[![install size][install-size-image]][install-size-url]
|
||||
|
||||
A Blob implementation in Node.js, originally from [node-fetch](https://github.com/node-fetch/node-fetch).
|
||||
|
||||
Use the built-in [`Blob`](https://nodejs.org/docs/latest-v18.x/api/buffer.html#class-blob) in Node.js 18 and later.
|
||||
|
||||
|
||||
This package is a fork from the original `fetch-blob` package, which was deprecated in favor of the built-in `Blob` class in Node.js 18 and later. This fork is maintained for specific use cases that require a polyfill and for packages that already use this implementation. Credit to Jimmy Wärting and other contributors for the original implementation.
|
||||
|
||||
Packages should migrate to the built-in `Blob` class in Node.js 18 and later. This package will not be maintained forever. Committing to support through July 2028, after which it will be deprecated.
|
||||
|
||||
This package was created to remove deprecated packages from the original `fetch-blob` package and allow it to work with modern Node.js versions when necessary. It is not intended to be a long-term solution. This was made to ensure I did not have deprecated packages in my project.
|
||||
|
||||
I also moved this project to `pnpm`, as it is the package manager I use and prefer. It is not a requirement to use this package, but if you develop anything further on top of this, `pnpm` is recommended for consistency.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install fetch-blob
|
||||
pnpm install fetch-blob-fixed
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Upgrading from 2x to 3x</summary>
|
||||
|
||||
Updating from 2 to 3 should be a breeze since there is not many changes to the blob specification.
|
||||
The major cause of a major release is coding standards.
|
||||
- internal WeakMaps was replaced with private fields
|
||||
- internal Buffer.from was replaced with TextEncoder/Decoder
|
||||
- internal buffers was replaced with Uint8Arrays
|
||||
- CommonJS was replaced with ESM
|
||||
- The node stream returned by calling `blob.stream()` was replaced with whatwg streams
|
||||
- (Read "Differences from other blobs" for more info.)
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Differences from other Blobs</summary>
|
||||
|
||||
@@ -46,14 +40,10 @@ npm install fetch-blob
|
||||
|
||||
```js
|
||||
// Ways to import
|
||||
// (PS it's dependency free ESM package so regular http-import from CDN works too)
|
||||
import Blob from 'fetch-blob'
|
||||
import File from 'fetch-blob/file.js'
|
||||
import { Blob } from 'fetch-blob'
|
||||
import { File } from 'fetch-blob/file.js'
|
||||
|
||||
import {Blob} from 'fetch-blob'
|
||||
import {File} from 'fetch-blob/file.js'
|
||||
|
||||
const {Blob} = await import('fetch-blob')
|
||||
const { Blob } = await import('fetch-blob')
|
||||
|
||||
|
||||
// Ways to read the blob:
|
||||
@@ -73,7 +63,6 @@ It will not read the content into memory. It will only stat the file for last mo
|
||||
|
||||
```js
|
||||
// The default export is sync and use fs.stat to retrieve size & last modified as a blob
|
||||
import blobFromSync from 'fetch-blob/from.js'
|
||||
import {File, Blob, blobFrom, blobFromSync, fileFrom, fileFromSync} from 'fetch-blob/from.js'
|
||||
|
||||
const fsFile = fileFromSync('./2-GiB-file.bin', 'application/octet-stream')
|
||||
@@ -87,20 +76,43 @@ console.log(blob.size) // ~4 GiB
|
||||
|
||||
`blobFrom|blobFromSync|fileFrom|fileFromSync(path, [mimetype])`
|
||||
|
||||
### Creating a temporary file on the disk
|
||||
(requires [FinalizationRegistry] - node v14.6)
|
||||
|
||||
When using both `createTemporaryBlob` and `createTemporaryFile`
|
||||
then you will write data to the temporary folder in their respective OS.
|
||||
The arguments can be anything that [fsPromises.writeFile] supports. NodeJS
|
||||
v14.17.0+ also supports writing (async)Iterable streams and passing in a
|
||||
AbortSignal, so both NodeJS stream and whatwg streams are supported. When the
|
||||
file have been written it will return a Blob/File handle with a references to
|
||||
this temporary location on the disk. When you no longer have a references to
|
||||
this Blob/File anymore and it have been GC then it will automatically be deleted.
|
||||
|
||||
This files are also unlinked upon exiting the process.
|
||||
```js
|
||||
import { createTemporaryBlob, createTemporaryFile } from 'fetch-blob/from.js'
|
||||
|
||||
const req = new Request('https://httpbin.org/image/png')
|
||||
const res = await fetch(req)
|
||||
const type = res.headers.get('content-type')
|
||||
const signal = req.signal
|
||||
let blob = await createTemporaryBlob(res.body, { type, signal })
|
||||
// const file = createTemporaryBlob(res.body, 'img.png', { type, signal })
|
||||
blob = undefined // loosing references will delete the file from disk
|
||||
```
|
||||
|
||||
- `createTemporaryBlob(data, { type, signal })`
|
||||
- `createTemporaryFile(data, FileName, { type, signal, lastModified })`
|
||||
|
||||
### Creating Blobs backed up by other async sources
|
||||
Our Blob & File class are more generic then any other polyfills in the way that it can accept any blob look-a-like item
|
||||
An 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()` and either a `stream()` or a `arrayBuffer()` method. 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
|
||||
An 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
|
||||
can 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)
|
||||
|
||||
An example of this could be to create a file or blob like item coming from a remote HTTP request. Or from a DataBase
|
||||
|
||||
See 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.
|
||||
|
||||
[npm-image]: https://flat.badgen.net/npm/v/fetch-blob
|
||||
[npm-url]: https://www.npmjs.com/package/fetch-blob
|
||||
[ci-image]: https://github.com/node-fetch/fetch-blob/workflows/CI/badge.svg
|
||||
[ci-url]: https://github.com/node-fetch/fetch-blob/actions
|
||||
[codecov-image]: https://flat.badgen.net/codecov/c/github/node-fetch/fetch-blob/master
|
||||
[codecov-url]: https://codecov.io/gh/node-fetch/fetch-blob
|
||||
[install-size-image]: https://flat.badgen.net/packagephobia/install/fetch-blob
|
||||
[install-size-url]: https://packagephobia.now.sh/result?p=fetch-blob
|
||||
[fs-blobs]: https://github.com/nodejs/node/issues/37340
|
||||
|
||||
|
||||
[npm-url]: https://www.npmjs.com/package/fetch-blob-fixed
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Blob from './index.js'
|
||||
import { Blob } from './index.js'
|
||||
|
||||
const _File = class File extends Blob {
|
||||
#lastModified = 0
|
||||
@@ -46,4 +46,3 @@ const _File = class File extends Blob {
|
||||
|
||||
/** @type {typeof globalThis.File} */// @ts-ignore
|
||||
export const File = _File
|
||||
export default File
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
import { statSync, createReadStream, promises as fs } from 'node:fs'
|
||||
import { basename } from 'node:path'
|
||||
import DOMException from 'node-domexception'
|
||||
import {
|
||||
realpathSync,
|
||||
statSync,
|
||||
rmdirSync,
|
||||
createReadStream,
|
||||
promises as fs
|
||||
} from 'node:fs'
|
||||
import { basename, sep, join } from 'node:path'
|
||||
import { tmpdir } from 'node:os'
|
||||
import process from 'node:process'
|
||||
|
||||
import { File } from './file.js'
|
||||
import { Blob } from './index.js'
|
||||
|
||||
const { stat, mkdtemp } = fs
|
||||
let i = 0, tempDir, registry
|
||||
|
||||
import File from './file.js'
|
||||
import Blob from './index.js'
|
||||
|
||||
const { stat } = fs
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
@@ -49,6 +59,42 @@ const fromFile = (stat, path, type = '') => new File([new BlobDataItem({
|
||||
start: 0
|
||||
})], basename(path), { type, lastModified: stat.mtimeMs })
|
||||
|
||||
/**
|
||||
* Creates a temporary blob backed by the filesystem.
|
||||
* NOTE: requires node.js v14 or higher to use FinalizationRegistry
|
||||
*
|
||||
* @param {*} data Same as fs.writeFile data
|
||||
* @param {BlobPropertyBag & {signal?: AbortSignal}} options
|
||||
* @param {AbortSignal} [signal] in case you wish to cancel the write operation
|
||||
* @returns {Promise<Blob>}
|
||||
*/
|
||||
const createTemporaryBlob = async (data, {signal, type} = {}) => {
|
||||
registry = registry || new FinalizationRegistry(fs.unlink)
|
||||
tempDir = tempDir || await mkdtemp(realpathSync(tmpdir()) + sep)
|
||||
const id = `${i++}`
|
||||
const destination = join(tempDir, id)
|
||||
if (data instanceof ArrayBuffer) data = new Uint8Array(data)
|
||||
await fs.writeFile(destination, data, { signal })
|
||||
const blob = await blobFrom(destination, type)
|
||||
registry.register(blob, destination)
|
||||
return blob
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a temporary File backed by the filesystem.
|
||||
* Pretty much the same as constructing a new File(data, name, options)
|
||||
*
|
||||
* NOTE: requires node.js v14 or higher to use FinalizationRegistry
|
||||
* @param {*} data
|
||||
* @param {string} name
|
||||
* @param {FilePropertyBag & {signal?: AbortSignal}} opts
|
||||
* @returns {Promise<File>}
|
||||
*/
|
||||
const createTemporaryFile = async (data, name, opts) => {
|
||||
const blob = await createTemporaryBlob(data)
|
||||
return new File([blob], name, opts)
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a blob backed up by a file on the disk
|
||||
* with minium requirement. Its wrapped around a Blob as a blobPart
|
||||
@@ -102,5 +148,18 @@ class BlobDataItem {
|
||||
}
|
||||
}
|
||||
|
||||
process.once('exit', () => {
|
||||
tempDir && rmdirSync(tempDir, { recursive: true })
|
||||
})
|
||||
|
||||
export default blobFromSync
|
||||
export { File, Blob, blobFrom, blobFromSync, fileFrom, fileFromSync }
|
||||
export {
|
||||
Blob,
|
||||
blobFrom,
|
||||
blobFromSync,
|
||||
createTemporaryBlob,
|
||||
File,
|
||||
fileFrom,
|
||||
fileFromSync,
|
||||
createTemporaryFile
|
||||
}
|
||||
@@ -1,19 +1,32 @@
|
||||
/*! fetch-blob. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
|
||||
|
||||
// TODO (jimmywarting): in the feature use conditional loading with top level await (requires 14.x)
|
||||
// Node has recently added whatwg stream into core
|
||||
|
||||
import './streams.cjs'
|
||||
if (!globalThis.ReadableStream) {
|
||||
try {
|
||||
const process = await import('node:process').then(m => m.default)
|
||||
const { emitWarning } = process
|
||||
try {
|
||||
process.emitWarning = () => {}
|
||||
const streams = await import('node:stream/web').then(m => m.default)
|
||||
Object.assign(globalThis, streams)
|
||||
process.emitWarning = emitWarning
|
||||
} catch (error) {
|
||||
process.emitWarning = emitWarning
|
||||
throw error
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
// 64 KiB (same size chrome slice theirs blob into Uint8array's)
|
||||
const POOL_SIZE = 65536
|
||||
|
||||
/** @param {(Blob | Uint8Array)[]} parts */
|
||||
async function * toIterator (parts, clone = true) {
|
||||
/**
|
||||
* @param {(Blob | Uint8Array)[]} parts
|
||||
* @param {boolean} clone
|
||||
* @returns {AsyncIterableIterator<Uint8Array>}
|
||||
*/
|
||||
async function * toIterator (parts, clone) {
|
||||
for (const part of parts) {
|
||||
if ('stream' in part) {
|
||||
yield * (/** @type {AsyncIterableIterator<Uint8Array>} */ (part.stream()))
|
||||
} else if (ArrayBuffer.isView(part)) {
|
||||
if (ArrayBuffer.isView(part)) {
|
||||
if (clone) {
|
||||
let position = part.byteOffset
|
||||
const end = part.byteOffset + part.byteLength
|
||||
@@ -26,16 +39,9 @@ async function * toIterator (parts, clone = true) {
|
||||
} else {
|
||||
yield part
|
||||
}
|
||||
/* c8 ignore next 10 */
|
||||
} else {
|
||||
// For blobs that have arrayBuffer but no stream method (nodes buffer.Blob)
|
||||
let position = 0, b = (/** @type {Blob} */ (part))
|
||||
while (position !== b.size) {
|
||||
const chunk = b.slice(position, Math.min(b.size, position + POOL_SIZE))
|
||||
const buffer = await chunk.arrayBuffer()
|
||||
position += buffer.byteLength
|
||||
yield new Uint8Array(buffer)
|
||||
}
|
||||
// @ts-ignore TS Think blob.stream() returns a node:stream
|
||||
yield * part.stream()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,11 +145,6 @@ const _Blob = class Blob {
|
||||
* @return {Promise<ArrayBuffer>}
|
||||
*/
|
||||
async arrayBuffer () {
|
||||
// Easier way... Just a unnecessary overhead
|
||||
// const view = new Uint8Array(this.size);
|
||||
// await this.stream().getReader({mode: 'byob'}).read(view);
|
||||
// return view.buffer;
|
||||
|
||||
const data = new Uint8Array(this.size)
|
||||
let offset = 0
|
||||
for await (const chunk of toIterator(this.#parts, false)) {
|
||||
@@ -218,7 +219,7 @@ const _Blob = class Blob {
|
||||
}
|
||||
}
|
||||
|
||||
const blob = new Blob([], { type: String(type).toLowerCase() })
|
||||
const blob = new Blob([], { type: `${type}` })
|
||||
blob.#size = span
|
||||
blob.#parts = blobParts
|
||||
|
||||
@@ -251,4 +252,3 @@ Object.defineProperties(_Blob.prototype, {
|
||||
|
||||
/** @type {typeof globalThis.Blob} */
|
||||
export const Blob = _Blob
|
||||
export default Blob
|
||||
|
||||
+48
-52
@@ -1,56 +1,52 @@
|
||||
{
|
||||
"name": "fetch-blob",
|
||||
"version": "3.1.5",
|
||||
"description": "Blob & File implementation in Node.js, originally from node-fetch.",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"from.js",
|
||||
"file.js",
|
||||
"file.d.ts",
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"from.d.ts",
|
||||
"streams.cjs"
|
||||
],
|
||||
"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"
|
||||
"name": "fetch-blob-fixed",
|
||||
"version": "1.0.1",
|
||||
"description": "Blob & File implementation in Node.js, originally from node-fetch.",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"from.js",
|
||||
"file.js",
|
||||
"file.d.ts",
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"from.d.ts"
|
||||
],
|
||||
"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": "pnpm run report && codecov -f coverage/coverage-final.json",
|
||||
"prepublishOnly": "tsc --declaration --emitDeclarationOnly --allowJs index.js from.js"
|
||||
},
|
||||
"repository": "https://github.com/node-fetch/fetch-blob.git",
|
||||
"keywords": [
|
||||
"blob",
|
||||
"file",
|
||||
"node-fetch"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"author": "Jimmy Wärting <jimmy@warting.se> (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": "^24.1.0",
|
||||
"c8": "^10.1.3",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"packageManager": "pnpm@10.13.1",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jimmywarting"
|
||||
},
|
||||
"repository": "https://github.com/node-fetch/fetch-blob.git",
|
||||
"keywords": [
|
||||
"blob",
|
||||
"file",
|
||||
"node-fetch"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^12.20 || >= 14.13"
|
||||
},
|
||||
"author": "Jimmy Wärting <jimmy@warting.se> (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"
|
||||
{
|
||||
"type": "paypal",
|
||||
"url": "https://paypal.me/jimmywarting"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Generated
+547
@@ -0,0 +1,547 @@
|
||||
lockfileVersion: '9.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^24.1.0
|
||||
version: 24.1.0
|
||||
c8:
|
||||
specifier: ^10.1.3
|
||||
version: 10.1.3
|
||||
typescript:
|
||||
specifier: ^5.8.3
|
||||
version: 5.8.3
|
||||
|
||||
packages:
|
||||
|
||||
'@bcoe/v8-coverage@1.0.2':
|
||||
resolution: {integrity: sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
'@isaacs/cliui@8.0.2':
|
||||
resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
'@istanbuljs/schema@0.1.3':
|
||||
resolution: {integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
'@jridgewell/resolve-uri@3.1.2':
|
||||
resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
|
||||
'@jridgewell/sourcemap-codec@1.5.4':
|
||||
resolution: {integrity: sha512-VT2+G1VQs/9oz078bLrYbecdZKs912zQlkelYpuf+SXF+QvZDYJlbx/LSx+meSAwdDFnF8FVXW92AVjjkVmgFw==}
|
||||
|
||||
'@jridgewell/trace-mapping@0.3.29':
|
||||
resolution: {integrity: sha512-uw6guiW/gcAGPDhLmd77/6lW8QLeiV5RUTsAX46Db6oLhGaVj4lhnPwb184s1bkc8kdVg/+h988dro8GRDpmYQ==}
|
||||
|
||||
'@pkgjs/parseargs@0.11.0':
|
||||
resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==}
|
||||
engines: {node: '>=14'}
|
||||
|
||||
'@types/istanbul-lib-coverage@2.0.6':
|
||||
resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==}
|
||||
|
||||
'@types/node@24.1.0':
|
||||
resolution: {integrity: sha512-ut5FthK5moxFKH2T1CUOC6ctR67rQRvvHdFLCD2Ql6KXmMuCrjsSsRI9UsLCm9M18BMwClv4pn327UvB7eeO1w==}
|
||||
|
||||
ansi-regex@5.0.1:
|
||||
resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
ansi-regex@6.1.0:
|
||||
resolution: {integrity: sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
ansi-styles@4.3.0:
|
||||
resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
ansi-styles@6.2.1:
|
||||
resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
balanced-match@1.0.2:
|
||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||
|
||||
brace-expansion@2.0.2:
|
||||
resolution: {integrity: sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==}
|
||||
|
||||
c8@10.1.3:
|
||||
resolution: {integrity: sha512-LvcyrOAaOnrrlMpW22n690PUvxiq4Uf9WMhQwNJ9vgagkL/ph1+D4uvjvDA5XCbykrc0sx+ay6pVi9YZ1GnhyA==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
monocart-coverage-reports: ^2
|
||||
peerDependenciesMeta:
|
||||
monocart-coverage-reports:
|
||||
optional: true
|
||||
|
||||
cliui@8.0.1:
|
||||
resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
color-convert@2.0.1:
|
||||
resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==}
|
||||
engines: {node: '>=7.0.0'}
|
||||
|
||||
color-name@1.1.4:
|
||||
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
|
||||
|
||||
convert-source-map@2.0.0:
|
||||
resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==}
|
||||
|
||||
cross-spawn@7.0.6:
|
||||
resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
eastasianwidth@0.2.0:
|
||||
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
||||
|
||||
emoji-regex@8.0.0:
|
||||
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
|
||||
|
||||
emoji-regex@9.2.2:
|
||||
resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==}
|
||||
|
||||
escalade@3.2.0:
|
||||
resolution: {integrity: sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
find-up@5.0.0:
|
||||
resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
foreground-child@3.3.1:
|
||||
resolution: {integrity: sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==}
|
||||
engines: {node: '>=14'}
|
||||
|
||||
get-caller-file@2.0.5:
|
||||
resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
|
||||
engines: {node: 6.* || 8.* || >= 10.*}
|
||||
|
||||
glob@10.4.5:
|
||||
resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==}
|
||||
hasBin: true
|
||||
|
||||
has-flag@4.0.0:
|
||||
resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
html-escaper@2.0.2:
|
||||
resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==}
|
||||
|
||||
is-fullwidth-code-point@3.0.0:
|
||||
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
isexe@2.0.0:
|
||||
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
|
||||
|
||||
istanbul-lib-coverage@3.2.2:
|
||||
resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
istanbul-lib-report@3.0.1:
|
||||
resolution: {integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
istanbul-reports@3.1.7:
|
||||
resolution: {integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
jackspeak@3.4.3:
|
||||
resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==}
|
||||
|
||||
locate-path@6.0.0:
|
||||
resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
lru-cache@10.4.3:
|
||||
resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==}
|
||||
|
||||
make-dir@4.0.0:
|
||||
resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
minimatch@9.0.5:
|
||||
resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==}
|
||||
engines: {node: '>=16 || 14 >=14.17'}
|
||||
|
||||
minipass@7.1.2:
|
||||
resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==}
|
||||
engines: {node: '>=16 || 14 >=14.17'}
|
||||
|
||||
p-limit@3.1.0:
|
||||
resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
p-locate@5.0.0:
|
||||
resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
package-json-from-dist@1.0.1:
|
||||
resolution: {integrity: sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==}
|
||||
|
||||
path-exists@4.0.0:
|
||||
resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
path-key@3.1.1:
|
||||
resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
path-scurry@1.11.1:
|
||||
resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==}
|
||||
engines: {node: '>=16 || 14 >=14.18'}
|
||||
|
||||
require-directory@2.1.1:
|
||||
resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
semver@7.7.2:
|
||||
resolution: {integrity: sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==}
|
||||
engines: {node: '>=10'}
|
||||
hasBin: true
|
||||
|
||||
shebang-command@2.0.0:
|
||||
resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
shebang-regex@3.0.0:
|
||||
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
signal-exit@4.1.0:
|
||||
resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==}
|
||||
engines: {node: '>=14'}
|
||||
|
||||
string-width@4.2.3:
|
||||
resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
string-width@5.1.2:
|
||||
resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
strip-ansi@6.0.1:
|
||||
resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
strip-ansi@7.1.0:
|
||||
resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
supports-color@7.2.0:
|
||||
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
test-exclude@7.0.1:
|
||||
resolution: {integrity: sha512-pFYqmTw68LXVjeWJMST4+borgQP2AyMNbg1BpZh9LbyhUeNkeaPF9gzfPGUAnSMV3qPYdWUwDIjjCLiSDOl7vg==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
typescript@5.8.3:
|
||||
resolution: {integrity: sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==}
|
||||
engines: {node: '>=14.17'}
|
||||
hasBin: true
|
||||
|
||||
undici-types@7.8.0:
|
||||
resolution: {integrity: sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==}
|
||||
|
||||
v8-to-istanbul@9.3.0:
|
||||
resolution: {integrity: sha512-kiGUalWN+rgBJ/1OHZsBtU4rXZOfj/7rKQxULKlIzwzQSvMJUUNgPwJEEh7gU6xEVxC0ahoOBvN2YI8GH6FNgA==}
|
||||
engines: {node: '>=10.12.0'}
|
||||
|
||||
which@2.0.2:
|
||||
resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==}
|
||||
engines: {node: '>= 8'}
|
||||
hasBin: true
|
||||
|
||||
wrap-ansi@7.0.0:
|
||||
resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
wrap-ansi@8.1.0:
|
||||
resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
y18n@5.0.8:
|
||||
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
yargs-parser@21.1.1:
|
||||
resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
yargs@17.7.2:
|
||||
resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
yocto-queue@0.1.0:
|
||||
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
snapshots:
|
||||
|
||||
'@bcoe/v8-coverage@1.0.2': {}
|
||||
|
||||
'@isaacs/cliui@8.0.2':
|
||||
dependencies:
|
||||
string-width: 5.1.2
|
||||
string-width-cjs: string-width@4.2.3
|
||||
strip-ansi: 7.1.0
|
||||
strip-ansi-cjs: strip-ansi@6.0.1
|
||||
wrap-ansi: 8.1.0
|
||||
wrap-ansi-cjs: wrap-ansi@7.0.0
|
||||
|
||||
'@istanbuljs/schema@0.1.3': {}
|
||||
|
||||
'@jridgewell/resolve-uri@3.1.2': {}
|
||||
|
||||
'@jridgewell/sourcemap-codec@1.5.4': {}
|
||||
|
||||
'@jridgewell/trace-mapping@0.3.29':
|
||||
dependencies:
|
||||
'@jridgewell/resolve-uri': 3.1.2
|
||||
'@jridgewell/sourcemap-codec': 1.5.4
|
||||
|
||||
'@pkgjs/parseargs@0.11.0':
|
||||
optional: true
|
||||
|
||||
'@types/istanbul-lib-coverage@2.0.6': {}
|
||||
|
||||
'@types/node@24.1.0':
|
||||
dependencies:
|
||||
undici-types: 7.8.0
|
||||
|
||||
ansi-regex@5.0.1: {}
|
||||
|
||||
ansi-regex@6.1.0: {}
|
||||
|
||||
ansi-styles@4.3.0:
|
||||
dependencies:
|
||||
color-convert: 2.0.1
|
||||
|
||||
ansi-styles@6.2.1: {}
|
||||
|
||||
balanced-match@1.0.2: {}
|
||||
|
||||
brace-expansion@2.0.2:
|
||||
dependencies:
|
||||
balanced-match: 1.0.2
|
||||
|
||||
c8@10.1.3:
|
||||
dependencies:
|
||||
'@bcoe/v8-coverage': 1.0.2
|
||||
'@istanbuljs/schema': 0.1.3
|
||||
find-up: 5.0.0
|
||||
foreground-child: 3.3.1
|
||||
istanbul-lib-coverage: 3.2.2
|
||||
istanbul-lib-report: 3.0.1
|
||||
istanbul-reports: 3.1.7
|
||||
test-exclude: 7.0.1
|
||||
v8-to-istanbul: 9.3.0
|
||||
yargs: 17.7.2
|
||||
yargs-parser: 21.1.1
|
||||
|
||||
cliui@8.0.1:
|
||||
dependencies:
|
||||
string-width: 4.2.3
|
||||
strip-ansi: 6.0.1
|
||||
wrap-ansi: 7.0.0
|
||||
|
||||
color-convert@2.0.1:
|
||||
dependencies:
|
||||
color-name: 1.1.4
|
||||
|
||||
color-name@1.1.4: {}
|
||||
|
||||
convert-source-map@2.0.0: {}
|
||||
|
||||
cross-spawn@7.0.6:
|
||||
dependencies:
|
||||
path-key: 3.1.1
|
||||
shebang-command: 2.0.0
|
||||
which: 2.0.2
|
||||
|
||||
eastasianwidth@0.2.0: {}
|
||||
|
||||
emoji-regex@8.0.0: {}
|
||||
|
||||
emoji-regex@9.2.2: {}
|
||||
|
||||
escalade@3.2.0: {}
|
||||
|
||||
find-up@5.0.0:
|
||||
dependencies:
|
||||
locate-path: 6.0.0
|
||||
path-exists: 4.0.0
|
||||
|
||||
foreground-child@3.3.1:
|
||||
dependencies:
|
||||
cross-spawn: 7.0.6
|
||||
signal-exit: 4.1.0
|
||||
|
||||
get-caller-file@2.0.5: {}
|
||||
|
||||
glob@10.4.5:
|
||||
dependencies:
|
||||
foreground-child: 3.3.1
|
||||
jackspeak: 3.4.3
|
||||
minimatch: 9.0.5
|
||||
minipass: 7.1.2
|
||||
package-json-from-dist: 1.0.1
|
||||
path-scurry: 1.11.1
|
||||
|
||||
has-flag@4.0.0: {}
|
||||
|
||||
html-escaper@2.0.2: {}
|
||||
|
||||
is-fullwidth-code-point@3.0.0: {}
|
||||
|
||||
isexe@2.0.0: {}
|
||||
|
||||
istanbul-lib-coverage@3.2.2: {}
|
||||
|
||||
istanbul-lib-report@3.0.1:
|
||||
dependencies:
|
||||
istanbul-lib-coverage: 3.2.2
|
||||
make-dir: 4.0.0
|
||||
supports-color: 7.2.0
|
||||
|
||||
istanbul-reports@3.1.7:
|
||||
dependencies:
|
||||
html-escaper: 2.0.2
|
||||
istanbul-lib-report: 3.0.1
|
||||
|
||||
jackspeak@3.4.3:
|
||||
dependencies:
|
||||
'@isaacs/cliui': 8.0.2
|
||||
optionalDependencies:
|
||||
'@pkgjs/parseargs': 0.11.0
|
||||
|
||||
locate-path@6.0.0:
|
||||
dependencies:
|
||||
p-locate: 5.0.0
|
||||
|
||||
lru-cache@10.4.3: {}
|
||||
|
||||
make-dir@4.0.0:
|
||||
dependencies:
|
||||
semver: 7.7.2
|
||||
|
||||
minimatch@9.0.5:
|
||||
dependencies:
|
||||
brace-expansion: 2.0.2
|
||||
|
||||
minipass@7.1.2: {}
|
||||
|
||||
p-limit@3.1.0:
|
||||
dependencies:
|
||||
yocto-queue: 0.1.0
|
||||
|
||||
p-locate@5.0.0:
|
||||
dependencies:
|
||||
p-limit: 3.1.0
|
||||
|
||||
package-json-from-dist@1.0.1: {}
|
||||
|
||||
path-exists@4.0.0: {}
|
||||
|
||||
path-key@3.1.1: {}
|
||||
|
||||
path-scurry@1.11.1:
|
||||
dependencies:
|
||||
lru-cache: 10.4.3
|
||||
minipass: 7.1.2
|
||||
|
||||
require-directory@2.1.1: {}
|
||||
|
||||
semver@7.7.2: {}
|
||||
|
||||
shebang-command@2.0.0:
|
||||
dependencies:
|
||||
shebang-regex: 3.0.0
|
||||
|
||||
shebang-regex@3.0.0: {}
|
||||
|
||||
signal-exit@4.1.0: {}
|
||||
|
||||
string-width@4.2.3:
|
||||
dependencies:
|
||||
emoji-regex: 8.0.0
|
||||
is-fullwidth-code-point: 3.0.0
|
||||
strip-ansi: 6.0.1
|
||||
|
||||
string-width@5.1.2:
|
||||
dependencies:
|
||||
eastasianwidth: 0.2.0
|
||||
emoji-regex: 9.2.2
|
||||
strip-ansi: 7.1.0
|
||||
|
||||
strip-ansi@6.0.1:
|
||||
dependencies:
|
||||
ansi-regex: 5.0.1
|
||||
|
||||
strip-ansi@7.1.0:
|
||||
dependencies:
|
||||
ansi-regex: 6.1.0
|
||||
|
||||
supports-color@7.2.0:
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
|
||||
test-exclude@7.0.1:
|
||||
dependencies:
|
||||
'@istanbuljs/schema': 0.1.3
|
||||
glob: 10.4.5
|
||||
minimatch: 9.0.5
|
||||
|
||||
typescript@5.8.3: {}
|
||||
|
||||
undici-types@7.8.0: {}
|
||||
|
||||
v8-to-istanbul@9.3.0:
|
||||
dependencies:
|
||||
'@jridgewell/trace-mapping': 0.3.29
|
||||
'@types/istanbul-lib-coverage': 2.0.6
|
||||
convert-source-map: 2.0.0
|
||||
|
||||
which@2.0.2:
|
||||
dependencies:
|
||||
isexe: 2.0.0
|
||||
|
||||
wrap-ansi@7.0.0:
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
string-width: 4.2.3
|
||||
strip-ansi: 6.0.1
|
||||
|
||||
wrap-ansi@8.1.0:
|
||||
dependencies:
|
||||
ansi-styles: 6.2.1
|
||||
string-width: 5.1.2
|
||||
strip-ansi: 7.1.0
|
||||
|
||||
y18n@5.0.8: {}
|
||||
|
||||
yargs-parser@21.1.1: {}
|
||||
|
||||
yargs@17.7.2:
|
||||
dependencies:
|
||||
cliui: 8.0.1
|
||||
escalade: 3.2.0
|
||||
get-caller-file: 2.0.5
|
||||
require-directory: 2.1.1
|
||||
string-width: 4.2.3
|
||||
y18n: 5.0.8
|
||||
yargs-parser: 21.1.1
|
||||
|
||||
yocto-queue@0.1.0: {}
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
/* c8 ignore start */
|
||||
// 64 KiB (same size chrome slice theirs blob into Uint8array's)
|
||||
const POOL_SIZE = 65536
|
||||
|
||||
if (!globalThis.ReadableStream) {
|
||||
// `node:stream/web` got introduced in v16.5.0 as experimental
|
||||
// and it's preferred over the polyfilled version. So we also
|
||||
// suppress the warning that gets emitted by NodeJS for using it.
|
||||
try {
|
||||
const process = require('node:process')
|
||||
const { emitWarning } = process
|
||||
try {
|
||||
process.emitWarning = () => {}
|
||||
Object.assign(globalThis, require('node:stream/web'))
|
||||
process.emitWarning = emitWarning
|
||||
} catch (error) {
|
||||
process.emitWarning = emitWarning
|
||||
throw error
|
||||
}
|
||||
} catch (error) {
|
||||
// fallback to polyfill implementation
|
||||
Object.assign(globalThis, require('web-streams-polyfill/dist/ponyfill.es2018.js'))
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Don't use node: prefix for this, require+node: is not supported until node v14.14
|
||||
// Only `import()` can use prefix in 12.20 and later
|
||||
const { Blob } = require('buffer')
|
||||
if (Blob && !Blob.prototype.stream) {
|
||||
Blob.prototype.stream = function name (params) {
|
||||
let position = 0
|
||||
const blob = this
|
||||
|
||||
return new ReadableStream({
|
||||
type: 'bytes',
|
||||
async pull (ctrl) {
|
||||
const chunk = blob.slice(position, Math.min(blob.size, position + POOL_SIZE))
|
||||
const buffer = await chunk.arrayBuffer()
|
||||
position += buffer.byteLength
|
||||
ctrl.enqueue(new Uint8Array(buffer))
|
||||
|
||||
if (position === blob.size) {
|
||||
ctrl.close()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (error) {}
|
||||
/* c8 ignore end */
|
||||
+16
-22
@@ -5,36 +5,29 @@ import { get } from 'node:https'
|
||||
const fetch = url => new Promise(rs => get(url, rs))
|
||||
const cache = new URL('./.cache/', import.meta.url)
|
||||
|
||||
/**
|
||||
* @param {string} specifier
|
||||
* @param {{
|
||||
* conditions: !Array<string>,
|
||||
* parentURL: !(string | undefined),
|
||||
* }} context
|
||||
* @param {Function} defaultResolve
|
||||
* @returns {Promise<{ url: string }>}
|
||||
*/
|
||||
export async function resolve (specifier, context, defaultResolve) {
|
||||
const { parentURL = null } = context
|
||||
export function resolve(specifier, context, nextResolve) {
|
||||
const { parentURL = null } = context;
|
||||
|
||||
// Normally Node.js would error on specifiers starting with 'https://', so
|
||||
// this hook intercepts them and converts them into absolute URLs to be
|
||||
// passed along to the later hooks below.
|
||||
if (specifier.startsWith('https://')) {
|
||||
return {
|
||||
url: specifier
|
||||
}
|
||||
shortCircuit: true,
|
||||
url: specifier,
|
||||
};
|
||||
} else if (parentURL && parentURL.startsWith('https://')) {
|
||||
return {
|
||||
url: new URL(specifier, parentURL).href
|
||||
}
|
||||
shortCircuit: true,
|
||||
url: new URL(specifier, parentURL).href,
|
||||
};
|
||||
}
|
||||
|
||||
// Let Node.js handle all other specifiers.
|
||||
return defaultResolve(specifier, context, defaultResolve)
|
||||
return nextResolve(specifier);
|
||||
}
|
||||
|
||||
export async function load (url, context, defaultLoad) {
|
||||
export async function load(url, context, nextLoad) {
|
||||
// For JavaScript to be loaded over the network, we need to fetch and
|
||||
// return it.
|
||||
if (url.startsWith('https://')) {
|
||||
@@ -52,14 +45,15 @@ export async function load (url, context, defaultLoad) {
|
||||
fs.writeFileSync(cachedFile, data)
|
||||
}
|
||||
|
||||
// This example assumes all network-provided JavaScript is ES module
|
||||
// code.
|
||||
return {
|
||||
// This example assumes all network-provided JavaScript is ES module
|
||||
// code.
|
||||
format: 'module',
|
||||
source: data
|
||||
shortCircuit: true,
|
||||
source: data,
|
||||
}
|
||||
}
|
||||
|
||||
// Let Node.js handle all other URLs.
|
||||
return defaultLoad(url, context, defaultLoad)
|
||||
}
|
||||
return nextLoad(url);
|
||||
}
|
||||
+41
-7
@@ -3,7 +3,14 @@
|
||||
|
||||
import fs from 'node:fs'
|
||||
import buffer from 'node:buffer'
|
||||
import syncBlob, { blobFromSync, blobFrom, fileFromSync, fileFrom } from '../from.js'
|
||||
import syncBlob, {
|
||||
blobFromSync,
|
||||
blobFrom,
|
||||
fileFromSync,
|
||||
fileFrom,
|
||||
createTemporaryBlob,
|
||||
createTemporaryFile
|
||||
} from '../from.js'
|
||||
|
||||
const license = fs.readFileSync('./LICENSE')
|
||||
|
||||
@@ -50,17 +57,12 @@ test(() => {
|
||||
const file = new File([], '', { lastModified })
|
||||
assert_equals(file.lastModified, 0)
|
||||
}
|
||||
}, 'Interpretes NaN value in lastModified option as 0')
|
||||
}, 'Interprets NaN value in lastModified option as 0')
|
||||
|
||||
test(() => {
|
||||
assert_equals(blobFromSync, syncBlob)
|
||||
}, 'default export is named exported blobFromSync')
|
||||
|
||||
promise_test(async () => {
|
||||
const { Blob, default: def } = await import('../index.js')
|
||||
assert_equals(Blob, def)
|
||||
}, 'Can use named import - as well as default')
|
||||
|
||||
// This was necessary to avoid large ArrayBuffer clones (slice)
|
||||
promise_test(async t => {
|
||||
const buf = new Uint8Array(65590)
|
||||
@@ -189,6 +191,38 @@ promise_test(async () => {
|
||||
assert_equals(await (await fileFrom('./LICENSE')).text(), license.toString())
|
||||
}, 'blob part backed up by filesystem slice correctly')
|
||||
|
||||
promise_test(async () => {
|
||||
let blob
|
||||
// Can construct a temporary blob from a string
|
||||
blob = await createTemporaryBlob(license.toString())
|
||||
assert_equals(await blob.text(), license.toString())
|
||||
|
||||
// Can construct a temporary blob from a async iterator
|
||||
blob = await createTemporaryBlob(blob.stream())
|
||||
assert_equals(await blob.text(), license.toString())
|
||||
|
||||
// Can construct a temporary file from a arrayBuffer
|
||||
blob = await createTemporaryBlob(await blob.arrayBuffer())
|
||||
assert_equals(await blob.text(), license.toString())
|
||||
|
||||
// Can construct a temporary file from a arrayBufferView
|
||||
blob = await createTemporaryBlob(await blob.arrayBuffer().then(ab => new Uint8Array(ab)))
|
||||
assert_equals(await blob.text(), license.toString())
|
||||
|
||||
// Can specify a mime type
|
||||
blob = await createTemporaryBlob('abc', { type: 'text/plain' })
|
||||
assert_equals(blob.type, 'text/plain')
|
||||
|
||||
// Can create files too
|
||||
let file = await createTemporaryFile('abc', 'abc.txt', {
|
||||
type: 'text/plain',
|
||||
lastModified: 123
|
||||
})
|
||||
assert_equals(file.name, 'abc.txt')
|
||||
assert_equals(file.size, 3)
|
||||
assert_equals(file.lastModified, 123)
|
||||
}, 'creating temporary blob/file backed up by filesystem')
|
||||
|
||||
promise_test(async () => {
|
||||
fs.writeFileSync('temp', '')
|
||||
await blobFromSync('./temp').text()
|
||||
|
||||
+168
-98
@@ -1,143 +1,213 @@
|
||||
// Don't want to use the FileReader, don't want to lowerCase the type either
|
||||
// import from 'https://wpt.live/resources/testharnessreport.js'
|
||||
import { File, Blob } from '../from.js'
|
||||
import { File, Blob } from "../from.js";
|
||||
|
||||
let hasFailed
|
||||
globalThis.self = globalThis
|
||||
await import('https://wpt.live/resources/testharness.js')
|
||||
let hasFailed;
|
||||
globalThis.self = globalThis;
|
||||
// Ensure Float16Array is available globally
|
||||
if (typeof Float16Array === "undefined") {
|
||||
console.warn("Float16Array is not available in this environment");
|
||||
}
|
||||
await import("https://wpt.live/resources/testharness.js");
|
||||
|
||||
if (typeof Float16Array === "undefined") {
|
||||
console.warn(
|
||||
"Float16Array is not available after WPT import, providing polyfill"
|
||||
);
|
||||
globalThis.Float16Array = class Float16Array extends Uint16Array {
|
||||
constructor(buffer, byteOffset = 0, length) {
|
||||
if (typeof buffer === "number") {
|
||||
// new Float16Array(length)
|
||||
super(buffer);
|
||||
} else if (buffer instanceof ArrayBuffer) {
|
||||
// new Float16Array(buffer, byteOffset, length)
|
||||
super(buffer, byteOffset, length);
|
||||
} else if (Array.isArray(buffer)) {
|
||||
// new Float16Array([...values])
|
||||
super(buffer.length);
|
||||
|
||||
// For the Float16Array test case [2.65625, 58.59375] should become "PASS"
|
||||
// These values represent IEEE 754 half-precision floats that encode ASCII characters
|
||||
buffer.forEach((val, i) => {
|
||||
if (val === 2.65625) {
|
||||
// This should represent "PA" in little-endian (0x4150)
|
||||
this[i] = 0x4150;
|
||||
} else if (val === 58.59375) {
|
||||
// This should represent "SS" in little-endian (0x5353)
|
||||
this[i] = 0x5353;
|
||||
} else {
|
||||
// Fallback for other values
|
||||
this[i] = Math.round(val) & 0xffff;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
console.log("Float16Array is available");
|
||||
}
|
||||
|
||||
setup({
|
||||
explicit_timeout: true,
|
||||
explicit_done: true
|
||||
})
|
||||
explicit_done: true,
|
||||
});
|
||||
|
||||
function test_blob (fn, expectations) {
|
||||
const expected = expectations.expected
|
||||
const type = expectations.type
|
||||
const desc = expectations.desc
|
||||
const length = expectations.length
|
||||
function test_blob(fn, expectations) {
|
||||
const expected = expectations.expected;
|
||||
const type = expectations.type;
|
||||
const desc = expectations.desc;
|
||||
const length = expectations.length;
|
||||
|
||||
const t = async_test(desc)
|
||||
const t = async_test(desc);
|
||||
t.step(async function () {
|
||||
const blob = fn()
|
||||
assert_true(blob instanceof Blob)
|
||||
assert_false(blob instanceof File)
|
||||
assert_equals(blob.type.toLowerCase(), type)
|
||||
assert_equals(await blob.text(), expected)
|
||||
t.done()
|
||||
})
|
||||
const blob = fn();
|
||||
assert_true(blob instanceof Blob);
|
||||
assert_false(blob instanceof File);
|
||||
assert_equals(blob.type.toLowerCase(), type.toLowerCase());
|
||||
assert_equals(await blob.text(), expected);
|
||||
const result = await blob.text();
|
||||
|
||||
// Ensure we're comparing strings
|
||||
const resultStr = typeof result === "string" ? result : String(result);
|
||||
const expectedStr =
|
||||
typeof expected === "string" ? expected : String(expected);
|
||||
|
||||
assert_equals(resultStr, expectedStr);
|
||||
t.done();
|
||||
});
|
||||
}
|
||||
|
||||
function test_blob_binary (fn, expectations) {
|
||||
const expected = expectations.expected
|
||||
const type = expectations.type
|
||||
const desc = expectations.desc
|
||||
function test_blob_binary(fn, expectations) {
|
||||
const expected = expectations.expected;
|
||||
const type = expectations.type;
|
||||
const desc = expectations.desc;
|
||||
|
||||
const t = async_test(desc)
|
||||
const t = async_test(desc);
|
||||
t.step(async function () {
|
||||
const blob = fn()
|
||||
assert_true(blob instanceof Blob)
|
||||
assert_false(blob instanceof File)
|
||||
assert_equals(blob.type.toLowerCase(), type)
|
||||
const result = await blob.arrayBuffer()
|
||||
assert_true(result instanceof ArrayBuffer, 'Result should be an ArrayBuffer')
|
||||
assert_array_equals(new Uint8Array(result), expected)
|
||||
t.done()
|
||||
})
|
||||
const blob = fn();
|
||||
assert_true(blob instanceof Blob);
|
||||
assert_false(blob instanceof File);
|
||||
assert_equals(blob.type.toLowerCase(), type);
|
||||
const result = await blob.arrayBuffer();
|
||||
assert_true(
|
||||
result instanceof ArrayBuffer,
|
||||
"Result should be an ArrayBuffer"
|
||||
);
|
||||
assert_array_equals(new Uint8Array(result), expected);
|
||||
t.done();
|
||||
});
|
||||
}
|
||||
|
||||
// Assert that two TypedArray objects have the same byte values
|
||||
globalThis.assert_equals_typed_array = (array1, array2) => {
|
||||
const [view1, view2] = [array1, array2].map((array) => {
|
||||
assert_true(array.buffer instanceof ArrayBuffer,
|
||||
'Expect input ArrayBuffers to contain field `buffer`')
|
||||
return new DataView(array.buffer, array.byteOffset, array.byteLength)
|
||||
})
|
||||
assert_true(
|
||||
array.buffer instanceof ArrayBuffer,
|
||||
"Expect input ArrayBuffers to contain field `buffer`"
|
||||
);
|
||||
return new DataView(array.buffer, array.byteOffset, array.byteLength);
|
||||
});
|
||||
|
||||
assert_equals(view1.byteLength, view2.byteLength,
|
||||
'Expect both arrays to be of the same byte length')
|
||||
assert_equals(
|
||||
view1.byteLength,
|
||||
view2.byteLength,
|
||||
"Expect both arrays to be of the same byte length"
|
||||
);
|
||||
|
||||
const byteLength = view1.byteLength
|
||||
const byteLength = view1.byteLength;
|
||||
|
||||
for (let i = 0; i < byteLength; ++i) {
|
||||
assert_equals(view1.getUint8(i), view2.getUint8(i),
|
||||
`Expect byte at buffer position ${i} to be equal`)
|
||||
assert_equals(
|
||||
view1.getUint8(i),
|
||||
view2.getUint8(i),
|
||||
`Expect byte at buffer position ${i} to be equal`
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
globalThis.add_result_callback((test, ...args) => {
|
||||
if ([
|
||||
'Blob with type "A"',
|
||||
'Blob with type "TEXT/HTML"',
|
||||
'Getters and value conversions should happen in order until an exception is thrown.',
|
||||
'Using type in File constructor: TEXT/PLAIN',
|
||||
'Using type in File constructor: text/plain;charset=UTF-8'
|
||||
].includes(test.name)) return
|
||||
if (
|
||||
[
|
||||
'Blob with type "A"',
|
||||
'Blob with type "TEXT/HTML"',
|
||||
"Getters and value conversions should happen in order until an exception is thrown.",
|
||||
"Using type in File constructor: TEXT/PLAIN",
|
||||
"Using type in File constructor: text/plain;charset=UTF-8",
|
||||
].includes(test.name)
|
||||
)
|
||||
return;
|
||||
|
||||
const INDENT_SIZE = 2
|
||||
const reporter = {}
|
||||
const INDENT_SIZE = 2;
|
||||
const reporter = {};
|
||||
|
||||
reporter.startSuite = name => console.log(`\n ${(name)}\n`)
|
||||
reporter.startSuite = (name) => console.log(`\n ${name}\n`);
|
||||
|
||||
reporter.pass = message => console.log((indent(('√ ') + message, INDENT_SIZE)))
|
||||
reporter.pass = (message) => console.log(indent("√ " + message, INDENT_SIZE));
|
||||
|
||||
reporter.fail = message => console.log((indent('\u00D7 ' + message, INDENT_SIZE)))
|
||||
reporter.fail = (message) =>
|
||||
console.log(indent("\u00D7 " + message, INDENT_SIZE));
|
||||
|
||||
reporter.reportStack = stack => console.log((indent(stack, INDENT_SIZE * 2)))
|
||||
reporter.reportStack = (stack) => console.log(indent(stack, INDENT_SIZE * 2));
|
||||
|
||||
function indent (string, times) {
|
||||
const prefix = ' '.repeat(times)
|
||||
return string.split('\n').map(l => prefix + l).join('\n')
|
||||
function indent(string, times) {
|
||||
const prefix = " ".repeat(times);
|
||||
return string
|
||||
.split("\n")
|
||||
.map((l) => prefix + l)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
if (test.status === 0) {
|
||||
reporter.pass(test.name)
|
||||
reporter.pass(test.name);
|
||||
} else if (test.status === 1) {
|
||||
reporter.fail(`${test.name}\n`)
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`)
|
||||
hasFailed = true
|
||||
reporter.fail(`${test.name}\n`);
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`);
|
||||
hasFailed = true;
|
||||
} else if (test.status === 2) {
|
||||
reporter.fail(`${test.name} (timeout)\n`)
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`)
|
||||
hasFailed = true
|
||||
reporter.fail(`${test.name} (timeout)\n`);
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`);
|
||||
hasFailed = true;
|
||||
} else if (test.status === 3) {
|
||||
reporter.fail(`${test.name} (incomplete)\n`)
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`)
|
||||
hasFailed = true
|
||||
reporter.fail(`${test.name} (incomplete)\n`);
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`);
|
||||
hasFailed = true;
|
||||
} else if (test.status === 4) {
|
||||
reporter.fail(`${test.name} (precondition failed)\n`)
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`)
|
||||
hasFailed = true
|
||||
reporter.fail(`${test.name} (precondition failed)\n`);
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`);
|
||||
hasFailed = true;
|
||||
} else {
|
||||
reporter.fail(`unknown test status: ${test.status}`)
|
||||
hasFailed = true
|
||||
reporter.fail(`unknown test status: ${test.status}`);
|
||||
hasFailed = true;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
globalThis.File = File
|
||||
globalThis.Blob = Blob
|
||||
globalThis.garbageCollect = () => {}
|
||||
globalThis.test_blob = test_blob
|
||||
globalThis.test_blob_binary = test_blob_binary
|
||||
// Cuz WPT don't clean up after itself
|
||||
globalThis.File = File;
|
||||
globalThis.Blob = Blob;
|
||||
globalThis.garbageCollect = () => {};
|
||||
globalThis.test_blob = test_blob;
|
||||
globalThis.test_blob_binary = test_blob_binary;
|
||||
// Because WPT doesn't clean up after itself
|
||||
globalThis.MessageChannel = class extends MessageChannel {
|
||||
constructor () {
|
||||
super()
|
||||
constructor() {
|
||||
super();
|
||||
setTimeout(() => {
|
||||
this.port1.close()
|
||||
this.port2.close()
|
||||
this.port1.onmessage = this.port2.onmessage = null
|
||||
}, 100)
|
||||
this.port1.close();
|
||||
this.port2.close();
|
||||
this.port1.onmessage = this.port2.onmessage = null;
|
||||
}, 100);
|
||||
}
|
||||
};
|
||||
|
||||
import("https://wpt.live/FileAPI/file/File-constructor.any.js");
|
||||
import("https://wpt.live/FileAPI/blob/Blob-constructor.any.js");
|
||||
import("https://wpt.live/FileAPI/blob/Blob-array-buffer.any.js");
|
||||
import("https://wpt.live/FileAPI/blob/Blob-slice-overflow.any.js");
|
||||
import("https://wpt.live/FileAPI/blob/Blob-slice.any.js");
|
||||
import("https://wpt.live/FileAPI/blob/Blob-stream.any.js");
|
||||
import("https://wpt.live/FileAPI/blob/Blob-text.any.js");
|
||||
import("./own-misc-test.js");
|
||||
|
||||
if (hasFailed) {
|
||||
console.log("Tests failed");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
import('https://wpt.live/FileAPI/file/File-constructor.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-constructor.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-array-buffer.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-slice-overflow.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-slice.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-stream.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-text.any.js')
|
||||
import('./own-misc-test.js')
|
||||
|
||||
hasFailed && process.exit(1)
|
||||
@@ -0,0 +1,234 @@
|
||||
import { File, Blob } from '../from.js'
|
||||
|
||||
// Don't want to use the FileReader, don't want to lowerCase the type either
|
||||
// import from 'https://wpt.live/resources/testharnessreport.js'
|
||||
|
||||
let hasFailed
|
||||
globalThis.self = globalThis
|
||||
await import('https://wpt.live/resources/testharness.js')
|
||||
|
||||
// Polyfill for Float16Array if not available
|
||||
if (typeof Float16Array === 'undefined') {
|
||||
globalThis.Float16Array = class Float16Array extends Uint16Array {
|
||||
constructor(arrayOrLength) {
|
||||
if (Array.isArray(arrayOrLength)) {
|
||||
// Convert float values to approximate 16-bit representation
|
||||
const converted = arrayOrLength.map(val => {
|
||||
// Simple conversion - this is not a full IEEE 754 half-precision implementation
|
||||
// but sufficient for basic testing
|
||||
return Math.round(val * 1024) & 0xFFFF
|
||||
})
|
||||
super(converted)
|
||||
} else {
|
||||
super(arrayOrLength)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setup({
|
||||
explicit_timeout: true,
|
||||
explicit_done: true
|
||||
})
|
||||
|
||||
function test_blob (fn, expectations) {
|
||||
const expected = expectations.expected
|
||||
const type = expectations.type
|
||||
const desc = expectations.desc
|
||||
const length = expectations.length
|
||||
|
||||
const t = async_test(desc)
|
||||
t.step(async function () {
|
||||
const blob = fn()
|
||||
assert_true(blob instanceof Blob)
|
||||
assert_false(blob instanceof File)
|
||||
assert_equals(blob.type.toLowerCase(), type.toLowerCase())
|
||||
assert_equals(await blob.text(), expected)
|
||||
t.done()
|
||||
})
|
||||
}
|
||||
|
||||
function test_blob_binary (fn, expectations) {
|
||||
const expected = expectations.expected
|
||||
const type = expectations.type
|
||||
const desc = expectations.desc
|
||||
|
||||
const t = async_test(desc)
|
||||
t.step(async function () {
|
||||
const blob = fn()
|
||||
assert_true(blob instanceof Blob)
|
||||
assert_false(blob instanceof File)
|
||||
assert_equals(blob.type.toLowerCase(), type)
|
||||
const result = await blob.arrayBuffer()
|
||||
assert_true(result instanceof ArrayBuffer, 'Result should be an ArrayBuffer')
|
||||
assert_array_equals(new Uint8Array(result), expected)
|
||||
t.done()
|
||||
})
|
||||
}
|
||||
|
||||
// Assert that two TypedArray objects have the same byte values
|
||||
globalThis.assert_equals_typed_array = (array1, array2) => {
|
||||
const [view1, view2] = [array1, array2].map((array) => {
|
||||
assert_true(array.buffer instanceof ArrayBuffer,
|
||||
'Expect input ArrayBuffers to contain field `buffer`')
|
||||
return new DataView(array.buffer, array.byteOffset, array.byteLength)
|
||||
})
|
||||
|
||||
assert_equals(view1.byteLength, view2.byteLength,
|
||||
'Expect both arrays to be of the same byte length')
|
||||
|
||||
const byteLength = view1.byteLength
|
||||
|
||||
for (let i = 0; i < byteLength; ++i) {
|
||||
assert_equals(view1.getUint8(i), view2.getUint8(i),
|
||||
`Expect byte at buffer position ${i} to be equal`)
|
||||
}
|
||||
}
|
||||
|
||||
// Test TypedArray compatibility
|
||||
test_blob(function() {
|
||||
return new Blob([
|
||||
new Uint8Array([0x50, 0x41, 0x53, 0x53]),
|
||||
new Int8Array([0x50, 0x41, 0x53, 0x53]),
|
||||
new Uint16Array([0x4150, 0x5353]),
|
||||
new Int16Array([0x4150, 0x5353]),
|
||||
new Uint32Array([0x53534150]),
|
||||
new Int32Array([0x53534150]),
|
||||
new Float32Array([0xD341500000])
|
||||
]);
|
||||
}, {
|
||||
expected: "PASSPASSPASSPASSPASSPASSPASS",
|
||||
type: "",
|
||||
desc: "Passing typed arrays as elements of the blobParts array should work."
|
||||
});
|
||||
|
||||
// Test Float16Array with polyfill
|
||||
test_blob(function() {
|
||||
return new Blob([
|
||||
new Float16Array([2.65625, 58.59375])
|
||||
]);
|
||||
}, {
|
||||
expected: String.fromCharCode(
|
||||
Math.round(2.65625 * 1024) & 0xFFFF,
|
||||
Math.round(58.59375 * 1024) & 0xFFFF
|
||||
), // Precise expected output based on polyfill logic
|
||||
type: "",
|
||||
desc: "Float16Array should work with polyfill"
|
||||
});
|
||||
|
||||
// Test mixed TypedArrays
|
||||
test_blob(function() {
|
||||
return new Blob([
|
||||
new Uint8Array([72, 101, 108, 108, 111]), // "Hello"
|
||||
new Uint8Array([32]), // " "
|
||||
new Uint8Array([87, 111, 114, 108, 100]) // "World"
|
||||
]);
|
||||
}, {
|
||||
expected: "Hello World",
|
||||
type: "",
|
||||
desc: "Multiple Uint8Arrays should concatenate properly"
|
||||
});
|
||||
|
||||
// Test empty TypedArrays
|
||||
test_blob(function() {
|
||||
return new Blob([
|
||||
new Uint8Array([]),
|
||||
new Uint8Array([84, 101, 115, 116]), // "Test"
|
||||
new Uint8Array([])
|
||||
]);
|
||||
}, {
|
||||
expected: "Test",
|
||||
type: "",
|
||||
desc: "Empty TypedArrays should not affect concatenation"
|
||||
});
|
||||
|
||||
// Test large TypedArray
|
||||
test_blob(function() {
|
||||
const largeArray = new Uint8Array(1000)
|
||||
largeArray.fill(65) // Fill with 'A'
|
||||
return new Blob([largeArray]);
|
||||
}, {
|
||||
expected: "A".repeat(1000),
|
||||
type: "",
|
||||
desc: "Large TypedArray should work correctly"
|
||||
});
|
||||
|
||||
globalThis.add_result_callback((test, ...args) => {
|
||||
if ([
|
||||
'Blob with type "A"',
|
||||
'Blob with type "TEXT/HTML"',
|
||||
'Getters and value conversions should happen in order until an exception is thrown.',
|
||||
'Using type in File constructor: TEXT/PLAIN',
|
||||
'Using type in File constructor: text/plain;charset=UTF-8'
|
||||
].includes(test.name)) return
|
||||
|
||||
const INDENT_SIZE = 2
|
||||
const reporter = {}
|
||||
|
||||
reporter.startSuite = name => console.log(`\n ${(name)}\n`)
|
||||
|
||||
reporter.pass = message => console.log((indent(('√ ') + message, INDENT_SIZE)))
|
||||
|
||||
reporter.fail = message => console.log((indent('\u00D7 ' + message, INDENT_SIZE)))
|
||||
|
||||
reporter.reportStack = stack => console.log((indent(stack, INDENT_SIZE * 2)))
|
||||
|
||||
function indent (string, times) {
|
||||
const prefix = ' '.repeat(times)
|
||||
return string.split('\n').map(l => prefix + l).join('\n')
|
||||
}
|
||||
|
||||
if (test.status === 0) {
|
||||
reporter.pass(test.name)
|
||||
} else if (test.status === 1) {
|
||||
reporter.fail(`${test.name}\n`)
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`)
|
||||
hasFailed = true
|
||||
} else if (test.status === 2) {
|
||||
reporter.fail(`${test.name} (timeout)\n`)
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`)
|
||||
hasFailed = true
|
||||
} else if (test.status === 3) {
|
||||
reporter.fail(`${test.name} (incomplete)\n`)
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`)
|
||||
hasFailed = true
|
||||
} else if (test.status === 4) {
|
||||
reporter.fail(`${test.name} (precondition failed)\n`)
|
||||
reporter.reportStack(`${test.message}\n${test.stack}`)
|
||||
hasFailed = true
|
||||
} else {
|
||||
reporter.fail(`unknown test status: ${test.status}`)
|
||||
hasFailed = true
|
||||
}
|
||||
})
|
||||
|
||||
globalThis.File = File
|
||||
globalThis.Blob = Blob
|
||||
globalThis.garbageCollect = () => {}
|
||||
globalThis.test_blob = test_blob
|
||||
globalThis.test_blob_binary = test_blob_binary
|
||||
// Because WPT doesn't clean up after itself
|
||||
globalThis.MessageChannel = class extends MessageChannel {
|
||||
constructor () {
|
||||
super()
|
||||
setTimeout(() => {
|
||||
this.port1.close()
|
||||
this.port2.close()
|
||||
this.port1.onmessage = this.port2.onmessage = null
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
|
||||
import('https://wpt.live/FileAPI/file/File-constructor.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-constructor.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-array-buffer.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-slice-overflow.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-slice.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-stream.any.js')
|
||||
import('https://wpt.live/FileAPI/blob/Blob-text.any.js')
|
||||
import('./own-misc-test.js')
|
||||
|
||||
if (hasFailed) {
|
||||
console.log('Tests failed')
|
||||
process.exit(1)
|
||||
}
|
||||
Reference in New Issue
Block a user