@common.js/fetch-blob 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/file.d.ts +2 -0
- package/file.js +275 -0
- package/from.d.ts +26 -0
- package/from.js +530 -0
- package/index.d.ts +3 -0
- package/index.js +1007 -0
- package/package.json +49 -0
- package/streams.cjs +51 -0
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@common.js/fetch-blob",
|
|
3
|
+
"version": "3.2.0",
|
|
4
|
+
"description": "fetch-blob package exported as CommonJS modules",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"files": [
|
|
8
|
+
"from.js",
|
|
9
|
+
"file.js",
|
|
10
|
+
"file.d.ts",
|
|
11
|
+
"index.js",
|
|
12
|
+
"index.d.ts",
|
|
13
|
+
"from.d.ts",
|
|
14
|
+
"streams.cjs"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node --experimental-loader ./test/http-loader.js ./test/test-wpt-in-node.js",
|
|
18
|
+
"report": "c8 --reporter json --reporter text npm run test",
|
|
19
|
+
"coverage": "npm run report && codecov -f coverage/coverage-final.json"
|
|
20
|
+
},
|
|
21
|
+
"repository": "etienne-martin/common.js",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": "^12.20 || >= 14.13"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/node-fetch/fetch-blob/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/etienne-martin/common.js#readme",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^17.0.9",
|
|
32
|
+
"c8": "^7.11.0",
|
|
33
|
+
"typescript": "^4.5.4"
|
|
34
|
+
},
|
|
35
|
+
"funding": [
|
|
36
|
+
{
|
|
37
|
+
"type": "github",
|
|
38
|
+
"url": "https://github.com/sponsors/jimmywarting"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"type": "paypal",
|
|
42
|
+
"url": "https://paypal.me/jimmywarting"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"node-domexception": "^1.0.0",
|
|
47
|
+
"web-streams-polyfill": "^3.0.3"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/streams.cjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* c8 ignore start */
|
|
2
|
+
// 64 KiB (same size chrome slice theirs blob into Uint8array's)
|
|
3
|
+
const POOL_SIZE = 65536
|
|
4
|
+
|
|
5
|
+
if (!globalThis.ReadableStream) {
|
|
6
|
+
// `node:stream/web` got introduced in v16.5.0 as experimental
|
|
7
|
+
// and it's preferred over the polyfilled version. So we also
|
|
8
|
+
// suppress the warning that gets emitted by NodeJS for using it.
|
|
9
|
+
try {
|
|
10
|
+
const process = require('node:process')
|
|
11
|
+
const { emitWarning } = process
|
|
12
|
+
try {
|
|
13
|
+
process.emitWarning = () => {}
|
|
14
|
+
Object.assign(globalThis, require('node:stream/web'))
|
|
15
|
+
process.emitWarning = emitWarning
|
|
16
|
+
} catch (error) {
|
|
17
|
+
process.emitWarning = emitWarning
|
|
18
|
+
throw error
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
// fallback to polyfill implementation
|
|
22
|
+
Object.assign(globalThis, require('web-streams-polyfill/dist/ponyfill.es2018.js'))
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
// Don't use node: prefix for this, require+node: is not supported until node v14.14
|
|
28
|
+
// Only `import()` can use prefix in 12.20 and later
|
|
29
|
+
const { Blob } = require('buffer')
|
|
30
|
+
if (Blob && !Blob.prototype.stream) {
|
|
31
|
+
Blob.prototype.stream = function name (params) {
|
|
32
|
+
let position = 0
|
|
33
|
+
const blob = this
|
|
34
|
+
|
|
35
|
+
return new ReadableStream({
|
|
36
|
+
type: 'bytes',
|
|
37
|
+
async pull (ctrl) {
|
|
38
|
+
const chunk = blob.slice(position, Math.min(blob.size, position + POOL_SIZE))
|
|
39
|
+
const buffer = await chunk.arrayBuffer()
|
|
40
|
+
position += buffer.byteLength
|
|
41
|
+
ctrl.enqueue(new Uint8Array(buffer))
|
|
42
|
+
|
|
43
|
+
if (position === blob.size) {
|
|
44
|
+
ctrl.close()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {}
|
|
51
|
+
/* c8 ignore end */
|