typeson-registry 14.1.0 → 14.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/dist/polyfills/SyncBlobFile.d.ts +33 -0
- package/dist/polyfills/SyncBlobFile.d.ts.map +1 -0
- package/dist/polyfills/URL.d.ts +23 -0
- package/dist/polyfills/URL.d.ts.map +1 -1
- package/dist/polyfills/index.d.ts +1 -0
- package/package.json +1 -1
- package/polyfills/SyncBlobFile.js +97 -0
- package/polyfills/URL.js +44 -3
- package/polyfills/index.cjs +153 -2
- package/polyfills/index.cjs.map +1 -1
- package/polyfills/index.js +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `Blob` subclass which also keeps a synchronously-readable copy of its
|
|
3
|
+
* content (accessible only via `getSyncBytes`, not as a property of the
|
|
4
|
+
* instance itself), for environments (e.g. Node without jsdom) where
|
|
5
|
+
* `Blob` alone offers no synchronous way to read it back.
|
|
6
|
+
*/
|
|
7
|
+
export class SyncBlob extends Blob {
|
|
8
|
+
/**
|
|
9
|
+
* @param {(string|ArrayBuffer|ArrayBufferView|Blob)[]} [parts]
|
|
10
|
+
* @param {BlobPropertyBag} [options]
|
|
11
|
+
*/
|
|
12
|
+
constructor(parts?: (string | ArrayBuffer | ArrayBufferView | Blob)[], options?: BlobPropertyBag);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* `File` counterpart to `SyncBlob` -- see its documentation for why this
|
|
16
|
+
* exists.
|
|
17
|
+
*/
|
|
18
|
+
export class SyncFile extends File {
|
|
19
|
+
/**
|
|
20
|
+
* @param {(string|ArrayBuffer|ArrayBufferView|Blob)[]} parts
|
|
21
|
+
* @param {string} name
|
|
22
|
+
* @param {FilePropertyBag} [options]
|
|
23
|
+
*/
|
|
24
|
+
constructor(parts: (string | ArrayBuffer | ArrayBufferView | Blob)[], name: string, options?: FilePropertyBag);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @param {Blob} blob A `SyncBlob`/`SyncFile` (or any `Blob`/`File` this
|
|
28
|
+
* module has otherwise recorded bytes for).
|
|
29
|
+
* @returns {Buffer|undefined} `undefined` if `blob` isn't one this module
|
|
30
|
+
* has a synchronous copy for.
|
|
31
|
+
*/
|
|
32
|
+
export function getSyncBytes(blob: Blob): Buffer | undefined;
|
|
33
|
+
//# sourceMappingURL=SyncBlobFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncBlobFile.d.ts","sourceRoot":"","sources":["../../polyfills/SyncBlobFile.js"],"names":[],"mappings":"AA6DA;;;;;GAKG;AACH;IACI;;;OAGG;IAGH,oBALW,CAAC,MAAM,GAAC,WAAW,GAAC,eAAe,GAAC,IAAI,CAAC,EAAE,YAC3C,eAAe,EAOzB;CACJ;AAED;;;GAGG;AACH;IACI;;;;OAIG;IACH,mBAJW,CAAC,MAAM,GAAC,WAAW,GAAC,eAAe,GAAC,IAAI,CAAC,EAAE,QAC3C,MAAM,YACN,eAAe,EAKzB;CACJ;AApED;;;;;GAKG;AACH,mCALW,IAAI,GAEF,MAAM,GAAC,SAAS,CAK5B"}
|
package/dist/polyfills/URL.d.ts
CHANGED
|
@@ -22,4 +22,27 @@ export function xmlHttpRequestOverrideMimeType({ polyfillDataURLs }?: {
|
|
|
22
22
|
* @returns {void}
|
|
23
23
|
*/
|
|
24
24
|
export function revokeObjectURL(blobURL: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves a `blob:` URL (previously registered via `createObjectURL`) back
|
|
27
|
+
* to its content, synchronously -- for use by any XHR/`fetch` polyfill
|
|
28
|
+
* that needs to serve `blob:` URLs itself (mirroring how browsers read
|
|
29
|
+
* `blob:` URLs without going over the network).
|
|
30
|
+
* @param {string} blobURL
|
|
31
|
+
* @returns {{type: string, bytes: Buffer}|undefined} `undefined` if
|
|
32
|
+
* `blobURL` is not (or is no longer) a registered `blob:` URL.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveObjectURL(blobURL: string): {
|
|
35
|
+
type: string;
|
|
36
|
+
bytes: Buffer;
|
|
37
|
+
} | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Synchronously reads the content of a `Blob`/`File` previously registered
|
|
40
|
+
* via `createObjectURL`. `SyncBlob`/`SyncFile` (see `SyncBlobFile.js`)
|
|
41
|
+
* keep their own synchronously-readable copy of the content for
|
|
42
|
+
* environments without jsdom (e.g. Node on its own); prefer that if
|
|
43
|
+
* present, falling back to jsdom's internal wrapper-unwrapping otherwise.
|
|
44
|
+
* @param {Blob} blob
|
|
45
|
+
* @returns {Buffer|undefined}
|
|
46
|
+
*/
|
|
47
|
+
export function getBlobBytesSync(blob: Blob): Buffer | undefined;
|
|
25
48
|
//# sourceMappingURL=URL.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"URL.d.ts","sourceRoot":"","sources":["../../polyfills/URL.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"URL.d.ts","sourceRoot":"","sources":["../../polyfills/URL.js"],"names":[],"mappings":"qDAgGW,MAAM,KACJ,IAAI;AArEjB;;;GAGG;AACH,sCAHW,IAAI,GACF,MAAM,CAgBlB;AAgDD;;;;GAIG;AAEH;;;;GAIG;AACH,sEAHG;IAAsB,gBAAgB;CACtC,GAAU,2BAA2B,CAoEvC;AA3HD;;;GAGG;AACH,yCAHW,MAAM,GACJ,IAAI,CAIhB;AAeD;;;;;;;;GAQG;AACH,0CAJW,MAAM,GACJ;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,GAAC,SAAS,CAcnD;AAjCD;;;;;;;;GAQG;AACH,uCAHW,IAAI,GACF,MAAM,GAAC,SAAS,CAI5B"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// @ts-nocheck -- Uses `Buffer`, which has no types without `@types/node`
|
|
2
|
+
// (matches `URL.js`'s own `@ts-nocheck`, also Node-runtime-specific)
|
|
3
|
+
// Node's native `Blob`/`File` only expose their bytes asynchronously
|
|
4
|
+
// (`.arrayBuffer()`/`.text()`/`.stream()`), with no standard synchronous
|
|
5
|
+
// accessor. `xmlHttpRequestOverrideMimeType` (see `URL.js`) needs
|
|
6
|
+
// synchronous access to back the `blob`/`file` types' synchronous
|
|
7
|
+
// `replace()`. For jsdom's own `Blob`/`File`, it gets this via jsdom's
|
|
8
|
+
// internal wrapper-unwrapping; for any other environment (e.g. Node
|
|
9
|
+
// without jsdom, as in a worker thread with no DOM), these
|
|
10
|
+
// `SyncBlob`/`SyncFile` subclasses provide the same synchronous access by
|
|
11
|
+
// capturing a copy of the content as a `Buffer`, at construction time,
|
|
12
|
+
// before handing the same `parts` off to the real, native constructor.
|
|
13
|
+
//
|
|
14
|
+
// The copy is kept in a module-private `WeakMap`, not as a property on the
|
|
15
|
+
// instance: a plain (even non-enumerable) property would let any code
|
|
16
|
+
// holding a reference to the `Blob`/`File` read its full raw content
|
|
17
|
+
// synchronously, bypassing the normal, async-only `Blob`/`File` API --
|
|
18
|
+
// and would risk leaking into `Object.keys()`/`JSON.stringify()`/etc. of
|
|
19
|
+
// an object that's supposed to look like an ordinary `Blob`/`File`. Only
|
|
20
|
+
// code that imports `getSyncBytes` from this same module can read it.
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @type {WeakMap<Blob, Buffer>}
|
|
24
|
+
*/
|
|
25
|
+
const syncBytesMap = new WeakMap();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Blob} blob A `SyncBlob`/`SyncFile` (or any `Blob`/`File` this
|
|
29
|
+
* module has otherwise recorded bytes for).
|
|
30
|
+
* @returns {Buffer|undefined} `undefined` if `blob` isn't one this module
|
|
31
|
+
* has a synchronous copy for.
|
|
32
|
+
*/
|
|
33
|
+
function getSyncBytes (blob) {
|
|
34
|
+
return syncBytesMap.get(blob);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {(string|ArrayBuffer|ArrayBufferView|Blob)[]} parts
|
|
39
|
+
* @returns {Buffer}
|
|
40
|
+
*/
|
|
41
|
+
function partsToBuffer (parts) {
|
|
42
|
+
return Buffer.concat(parts.map((part) => {
|
|
43
|
+
if (typeof part === 'string') {
|
|
44
|
+
return Buffer.from(part, 'utf8');
|
|
45
|
+
}
|
|
46
|
+
if (Object.prototype.toString.call(part) === '[object ArrayBuffer]') {
|
|
47
|
+
return Buffer.from(/** @type {ArrayBuffer} */ (part));
|
|
48
|
+
}
|
|
49
|
+
if (ArrayBuffer.isView(part)) {
|
|
50
|
+
return Buffer.from(
|
|
51
|
+
part.buffer, part.byteOffset, part.byteLength
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const partBytes = part && syncBytesMap.get(/** @type {Blob} */ (part));
|
|
55
|
+
if (partBytes) {
|
|
56
|
+
return partBytes;
|
|
57
|
+
}
|
|
58
|
+
return Buffer.from(String(part), 'utf8');
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A `Blob` subclass which also keeps a synchronously-readable copy of its
|
|
64
|
+
* content (accessible only via `getSyncBytes`, not as a property of the
|
|
65
|
+
* instance itself), for environments (e.g. Node without jsdom) where
|
|
66
|
+
* `Blob` alone offers no synchronous way to read it back.
|
|
67
|
+
*/
|
|
68
|
+
class SyncBlob extends Blob {
|
|
69
|
+
/**
|
|
70
|
+
* @param {(string|ArrayBuffer|ArrayBufferView|Blob)[]} [parts]
|
|
71
|
+
* @param {BlobPropertyBag} [options]
|
|
72
|
+
*/
|
|
73
|
+
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
74
|
+
// eslint-disable-next-line default-param-last -- Must match native `Blob` positionally
|
|
75
|
+
constructor (parts = [], options) {
|
|
76
|
+
super(parts, options);
|
|
77
|
+
syncBytesMap.set(this, partsToBuffer(parts));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* `File` counterpart to `SyncBlob` -- see its documentation for why this
|
|
83
|
+
* exists.
|
|
84
|
+
*/
|
|
85
|
+
class SyncFile extends File {
|
|
86
|
+
/**
|
|
87
|
+
* @param {(string|ArrayBuffer|ArrayBufferView|Blob)[]} parts
|
|
88
|
+
* @param {string} name
|
|
89
|
+
* @param {FilePropertyBag} [options]
|
|
90
|
+
*/
|
|
91
|
+
constructor (parts, name, options) {
|
|
92
|
+
super(parts, name, options);
|
|
93
|
+
syncBytesMap.set(this, partsToBuffer(parts));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export {SyncBlob, SyncFile, getSyncBytes};
|
package/polyfills/URL.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import {createRequire} from 'node:module';
|
|
15
15
|
import whatwgURL from 'whatwg-url';
|
|
16
16
|
import generateUUID from '../utils/generateUUID.js';
|
|
17
|
+
import {getSyncBytes} from './SyncBlobFile.js';
|
|
17
18
|
|
|
18
19
|
const require = createRequire(import.meta.url);
|
|
19
20
|
const {implForWrapper} = require('jsdom/lib/generated/idl/utils.js');
|
|
@@ -53,6 +54,41 @@ const revokeObjectURL = function (blobURL) {
|
|
|
53
54
|
delete blobURLs[blobURL];
|
|
54
55
|
};
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Synchronously reads the content of a `Blob`/`File` previously registered
|
|
59
|
+
* via `createObjectURL`. `SyncBlob`/`SyncFile` (see `SyncBlobFile.js`)
|
|
60
|
+
* keep their own synchronously-readable copy of the content for
|
|
61
|
+
* environments without jsdom (e.g. Node on its own); prefer that if
|
|
62
|
+
* present, falling back to jsdom's internal wrapper-unwrapping otherwise.
|
|
63
|
+
* @param {Blob} blob
|
|
64
|
+
* @returns {Buffer|undefined}
|
|
65
|
+
*/
|
|
66
|
+
const getBlobBytesSync = function (blob) {
|
|
67
|
+
return getSyncBytes(blob) || implForWrapper(blob)?._bytes;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Resolves a `blob:` URL (previously registered via `createObjectURL`) back
|
|
72
|
+
* to its content, synchronously -- for use by any XHR/`fetch` polyfill
|
|
73
|
+
* that needs to serve `blob:` URLs itself (mirroring how browsers read
|
|
74
|
+
* `blob:` URLs without going over the network).
|
|
75
|
+
* @param {string} blobURL
|
|
76
|
+
* @returns {{type: string, bytes: Buffer}|undefined} `undefined` if
|
|
77
|
+
* `blobURL` is not (or is no longer) a registered `blob:` URL.
|
|
78
|
+
*/
|
|
79
|
+
const resolveObjectURL = function (blobURL) {
|
|
80
|
+
const blob = blobURLs[blobURL];
|
|
81
|
+
if (!blob) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
// eslint-disable-next-line n/no-sync -- Deliberate
|
|
85
|
+
const bytes = getBlobBytesSync(blob);
|
|
86
|
+
if (!bytes) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return {type: blob.type, bytes};
|
|
90
|
+
};
|
|
91
|
+
|
|
56
92
|
// We only handle the case of binary, so no need to override `open`
|
|
57
93
|
// in all cases; but this only works if override is called first
|
|
58
94
|
|
|
@@ -98,11 +134,13 @@ const xmlHttpRequestOverrideMimeType = function (
|
|
|
98
134
|
}
|
|
99
135
|
const responseType = 'text/plain'; // blob.type;
|
|
100
136
|
// utf16le and base64 both convert lone surrogates
|
|
101
|
-
|
|
137
|
+
|
|
138
|
+
// eslint-disable-next-line n/no-sync -- Deliberate
|
|
139
|
+
const syncBytes = getBlobBytesSync(blob);
|
|
102
140
|
// jsdom changed Blob internals from `_buffer`
|
|
103
141
|
// to `_bytes`; support both.
|
|
104
142
|
const encoded =
|
|
105
|
-
Buffer.from(
|
|
143
|
+
Buffer.from(syncBytes).toString('binary');
|
|
106
144
|
|
|
107
145
|
// Not usable in jsdom which makes properties readonly,
|
|
108
146
|
// but local-xmlhttprequest can use (and jsdom can
|
|
@@ -133,4 +171,7 @@ const xmlHttpRequestOverrideMimeType = function (
|
|
|
133
171
|
};
|
|
134
172
|
};
|
|
135
173
|
|
|
136
|
-
export {
|
|
174
|
+
export {
|
|
175
|
+
createObjectURL, xmlHttpRequestOverrideMimeType, revokeObjectURL,
|
|
176
|
+
resolveObjectURL, getBlobBytesSync
|
|
177
|
+
};
|
package/polyfills/index.cjs
CHANGED
|
@@ -3342,6 +3342,111 @@ function generateUUID() {
|
|
|
3342
3342
|
});
|
|
3343
3343
|
}
|
|
3344
3344
|
|
|
3345
|
+
// @ts-nocheck -- Uses `Buffer`, which has no types without `@types/node`
|
|
3346
|
+
// (matches `URL.js`'s own `@ts-nocheck`, also Node-runtime-specific)
|
|
3347
|
+
// Node's native `Blob`/`File` only expose their bytes asynchronously
|
|
3348
|
+
// (`.arrayBuffer()`/`.text()`/`.stream()`), with no standard synchronous
|
|
3349
|
+
// accessor. `xmlHttpRequestOverrideMimeType` (see `URL.js`) needs
|
|
3350
|
+
// synchronous access to back the `blob`/`file` types' synchronous
|
|
3351
|
+
// `replace()`. For jsdom's own `Blob`/`File`, it gets this via jsdom's
|
|
3352
|
+
// internal wrapper-unwrapping; for any other environment (e.g. Node
|
|
3353
|
+
// without jsdom, as in a worker thread with no DOM), these
|
|
3354
|
+
// `SyncBlob`/`SyncFile` subclasses provide the same synchronous access by
|
|
3355
|
+
// capturing a copy of the content as a `Buffer`, at construction time,
|
|
3356
|
+
// before handing the same `parts` off to the real, native constructor.
|
|
3357
|
+
//
|
|
3358
|
+
// The copy is kept in a module-private `WeakMap`, not as a property on the
|
|
3359
|
+
// instance: a plain (even non-enumerable) property would let any code
|
|
3360
|
+
// holding a reference to the `Blob`/`File` read its full raw content
|
|
3361
|
+
// synchronously, bypassing the normal, async-only `Blob`/`File` API --
|
|
3362
|
+
// and would risk leaking into `Object.keys()`/`JSON.stringify()`/etc. of
|
|
3363
|
+
// an object that's supposed to look like an ordinary `Blob`/`File`. Only
|
|
3364
|
+
// code that imports `getSyncBytes` from this same module can read it.
|
|
3365
|
+
|
|
3366
|
+
/**
|
|
3367
|
+
* @type {WeakMap<Blob, Buffer>}
|
|
3368
|
+
*/
|
|
3369
|
+
var syncBytesMap = new WeakMap();
|
|
3370
|
+
|
|
3371
|
+
/**
|
|
3372
|
+
* @param {Blob} blob A `SyncBlob`/`SyncFile` (or any `Blob`/`File` this
|
|
3373
|
+
* module has otherwise recorded bytes for).
|
|
3374
|
+
* @returns {Buffer|undefined} `undefined` if `blob` isn't one this module
|
|
3375
|
+
* has a synchronous copy for.
|
|
3376
|
+
*/
|
|
3377
|
+
function getSyncBytes(blob) {
|
|
3378
|
+
return syncBytesMap.get(blob);
|
|
3379
|
+
}
|
|
3380
|
+
|
|
3381
|
+
/**
|
|
3382
|
+
* @param {(string|ArrayBuffer|ArrayBufferView|Blob)[]} parts
|
|
3383
|
+
* @returns {Buffer}
|
|
3384
|
+
*/
|
|
3385
|
+
function partsToBuffer(parts) {
|
|
3386
|
+
return Buffer.concat(parts.map(function (part) {
|
|
3387
|
+
if (typeof part === 'string') {
|
|
3388
|
+
return Buffer.from(part, 'utf8');
|
|
3389
|
+
}
|
|
3390
|
+
if (Object.prototype.toString.call(part) === '[object ArrayBuffer]') {
|
|
3391
|
+
return Buffer.from(/** @type {ArrayBuffer} */part);
|
|
3392
|
+
}
|
|
3393
|
+
if (ArrayBuffer.isView(part)) {
|
|
3394
|
+
return Buffer.from(part.buffer, part.byteOffset, part.byteLength);
|
|
3395
|
+
}
|
|
3396
|
+
var partBytes = part && syncBytesMap.get(/** @type {Blob} */part);
|
|
3397
|
+
if (partBytes) {
|
|
3398
|
+
return partBytes;
|
|
3399
|
+
}
|
|
3400
|
+
return Buffer.from(String(part), 'utf8');
|
|
3401
|
+
}));
|
|
3402
|
+
}
|
|
3403
|
+
|
|
3404
|
+
/**
|
|
3405
|
+
* A `Blob` subclass which also keeps a synchronously-readable copy of its
|
|
3406
|
+
* content (accessible only via `getSyncBytes`, not as a property of the
|
|
3407
|
+
* instance itself), for environments (e.g. Node without jsdom) where
|
|
3408
|
+
* `Blob` alone offers no synchronous way to read it back.
|
|
3409
|
+
*/
|
|
3410
|
+
var SyncBlob = /*#__PURE__*/function (_Blob) {
|
|
3411
|
+
/**
|
|
3412
|
+
* @param {(string|ArrayBuffer|ArrayBufferView|Blob)[]} [parts]
|
|
3413
|
+
* @param {BlobPropertyBag} [options]
|
|
3414
|
+
*/
|
|
3415
|
+
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
3416
|
+
// eslint-disable-next-line default-param-last -- Must match native `Blob` positionally
|
|
3417
|
+
function SyncBlob() {
|
|
3418
|
+
var _this;
|
|
3419
|
+
var parts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3420
|
+
var options = arguments.length > 1 ? arguments[1] : undefined;
|
|
3421
|
+
_classCallCheck(this, SyncBlob);
|
|
3422
|
+
_this = _callSuper(this, SyncBlob, [parts, options]);
|
|
3423
|
+
syncBytesMap.set(_this, partsToBuffer(parts));
|
|
3424
|
+
return _this;
|
|
3425
|
+
}
|
|
3426
|
+
_inherits(SyncBlob, _Blob);
|
|
3427
|
+
return _createClass(SyncBlob);
|
|
3428
|
+
}(/*#__PURE__*/_wrapNativeSuper(Blob));
|
|
3429
|
+
/**
|
|
3430
|
+
* `File` counterpart to `SyncBlob` -- see its documentation for why this
|
|
3431
|
+
* exists.
|
|
3432
|
+
*/
|
|
3433
|
+
var SyncFile = /*#__PURE__*/function (_File) {
|
|
3434
|
+
/**
|
|
3435
|
+
* @param {(string|ArrayBuffer|ArrayBufferView|Blob)[]} parts
|
|
3436
|
+
* @param {string} name
|
|
3437
|
+
* @param {FilePropertyBag} [options]
|
|
3438
|
+
*/
|
|
3439
|
+
function SyncFile(parts, name, options) {
|
|
3440
|
+
var _this2;
|
|
3441
|
+
_classCallCheck(this, SyncFile);
|
|
3442
|
+
_this2 = _callSuper(this, SyncFile, [parts, name, options]);
|
|
3443
|
+
syncBytesMap.set(_this2, partsToBuffer(parts));
|
|
3444
|
+
return _this2;
|
|
3445
|
+
}
|
|
3446
|
+
_inherits(SyncFile, _File);
|
|
3447
|
+
return _createClass(SyncFile);
|
|
3448
|
+
}(/*#__PURE__*/_wrapNativeSuper(File));
|
|
3449
|
+
|
|
3345
3450
|
/* eslint-disable unicorn/no-this-outside-of-class -- Monkey-patching */
|
|
3346
3451
|
// @ts-nocheck -- jsdom has no types for the file we need
|
|
3347
3452
|
/* globals location, XMLHttpRequest -- Polyfills */
|
|
@@ -3380,6 +3485,45 @@ var revokeObjectURL = function revokeObjectURL(blobURL) {
|
|
|
3380
3485
|
delete blobURLs[blobURL];
|
|
3381
3486
|
};
|
|
3382
3487
|
|
|
3488
|
+
/**
|
|
3489
|
+
* Synchronously reads the content of a `Blob`/`File` previously registered
|
|
3490
|
+
* via `createObjectURL`. `SyncBlob`/`SyncFile` (see `SyncBlobFile.js`)
|
|
3491
|
+
* keep their own synchronously-readable copy of the content for
|
|
3492
|
+
* environments without jsdom (e.g. Node on its own); prefer that if
|
|
3493
|
+
* present, falling back to jsdom's internal wrapper-unwrapping otherwise.
|
|
3494
|
+
* @param {Blob} blob
|
|
3495
|
+
* @returns {Buffer|undefined}
|
|
3496
|
+
*/
|
|
3497
|
+
var getBlobBytesSync = function getBlobBytesSync(blob) {
|
|
3498
|
+
var _implForWrapper;
|
|
3499
|
+
return getSyncBytes(blob) || ((_implForWrapper = implForWrapper(blob)) === null || _implForWrapper === void 0 ? void 0 : _implForWrapper._bytes);
|
|
3500
|
+
};
|
|
3501
|
+
|
|
3502
|
+
/**
|
|
3503
|
+
* Resolves a `blob:` URL (previously registered via `createObjectURL`) back
|
|
3504
|
+
* to its content, synchronously -- for use by any XHR/`fetch` polyfill
|
|
3505
|
+
* that needs to serve `blob:` URLs itself (mirroring how browsers read
|
|
3506
|
+
* `blob:` URLs without going over the network).
|
|
3507
|
+
* @param {string} blobURL
|
|
3508
|
+
* @returns {{type: string, bytes: Buffer}|undefined} `undefined` if
|
|
3509
|
+
* `blobURL` is not (or is no longer) a registered `blob:` URL.
|
|
3510
|
+
*/
|
|
3511
|
+
var resolveObjectURL = function resolveObjectURL(blobURL) {
|
|
3512
|
+
var blob = blobURLs[blobURL];
|
|
3513
|
+
if (!blob) {
|
|
3514
|
+
return undefined;
|
|
3515
|
+
}
|
|
3516
|
+
// eslint-disable-next-line n/no-sync -- Deliberate
|
|
3517
|
+
var bytes = getBlobBytesSync(blob);
|
|
3518
|
+
if (!bytes) {
|
|
3519
|
+
return undefined;
|
|
3520
|
+
}
|
|
3521
|
+
return {
|
|
3522
|
+
type: blob.type,
|
|
3523
|
+
bytes: bytes
|
|
3524
|
+
};
|
|
3525
|
+
};
|
|
3526
|
+
|
|
3383
3527
|
// We only handle the case of binary, so no need to override `open`
|
|
3384
3528
|
// in all cases; but this only works if override is called first
|
|
3385
3529
|
|
|
@@ -3420,10 +3564,12 @@ var xmlHttpRequestOverrideMimeType = function xmlHttpRequestOverrideMimeType() {
|
|
|
3420
3564
|
}
|
|
3421
3565
|
var responseType = 'text/plain'; // blob.type;
|
|
3422
3566
|
// utf16le and base64 both convert lone surrogates
|
|
3423
|
-
|
|
3567
|
+
|
|
3568
|
+
// eslint-disable-next-line n/no-sync -- Deliberate
|
|
3569
|
+
var syncBytes = getBlobBytesSync(blob);
|
|
3424
3570
|
// jsdom changed Blob internals from `_buffer`
|
|
3425
3571
|
// to `_bytes`; support both.
|
|
3426
|
-
var encoded = Buffer.from(
|
|
3572
|
+
var encoded = Buffer.from(syncBytes).toString('binary');
|
|
3427
3573
|
|
|
3428
3574
|
// Not usable in jsdom which makes properties readonly,
|
|
3429
3575
|
// but local-xmlhttprequest can use (and jsdom can
|
|
@@ -4692,10 +4838,15 @@ exports.DOMRectReadOnly = DOMRectReadOnly;
|
|
|
4692
4838
|
exports.EncodedAudioChunk = EncodedAudioChunk;
|
|
4693
4839
|
exports.EncodedVideoChunk = EncodedVideoChunk;
|
|
4694
4840
|
exports.QuotaExceededError = QuotaExceededError;
|
|
4841
|
+
exports.SyncBlob = SyncBlob;
|
|
4842
|
+
exports.SyncFile = SyncFile;
|
|
4695
4843
|
exports.VideoFrame = VideoFrame;
|
|
4696
4844
|
exports.WebTransportError = WebTransportError;
|
|
4697
4845
|
exports.createImageBitmap = createImageBitmap;
|
|
4698
4846
|
exports.createObjectURL = createObjectURL;
|
|
4847
|
+
exports.getBlobBytesSync = getBlobBytesSync;
|
|
4848
|
+
exports.getSyncBytes = getSyncBytes;
|
|
4849
|
+
exports.resolveObjectURL = resolveObjectURL;
|
|
4699
4850
|
exports.revokeObjectURL = revokeObjectURL;
|
|
4700
4851
|
exports.xmlHttpRequestOverrideMimeType = xmlHttpRequestOverrideMimeType;
|
|
4701
4852
|
//# sourceMappingURL=index.cjs.map
|