mediabunny 1.3.0 → 1.3.2
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/README.md +2 -0
- package/dist/bundles/mediabunny.cjs +22 -3
- package/dist/bundles/mediabunny.min.cjs +4 -4
- package/dist/bundles/mediabunny.min.mjs +4 -4
- package/dist/bundles/mediabunny.mjs +22 -3
- package/dist/modules/misc.js +1 -1
- package/dist/modules/source.d.ts.map +1 -1
- package/dist/modules/source.js +23 -2
- package/package.json +2 -2
- package/src/misc.ts +3 -3
- package/src/source.ts +27 -2
|
@@ -382,12 +382,12 @@ var retriedFetch = async (url2, requestInit, getRetryDelay) => {
|
|
|
382
382
|
try {
|
|
383
383
|
return await fetch(url2, requestInit);
|
|
384
384
|
} catch (error) {
|
|
385
|
-
console.error("Retrying failed fetch. Error:", error);
|
|
386
385
|
attempts++;
|
|
387
386
|
const retryDelayInSeconds = getRetryDelay(attempts);
|
|
388
387
|
if (retryDelayInSeconds === null) {
|
|
389
388
|
throw error;
|
|
390
389
|
}
|
|
390
|
+
console.error("Retrying failed fetch. Error:", error);
|
|
391
391
|
if (!Number.isFinite(retryDelayInSeconds) || retryDelayInSeconds < 0) {
|
|
392
392
|
throw new TypeError("Retry delay must be a non-negative finite number.");
|
|
393
393
|
}
|
|
@@ -11580,7 +11580,7 @@ var UrlSource = class extends Source {
|
|
|
11580
11580
|
throw new Error(`Error fetching ${this._url}: ${response.status} ${response.statusText}`);
|
|
11581
11581
|
}
|
|
11582
11582
|
const buffer = await response.arrayBuffer();
|
|
11583
|
-
if (
|
|
11583
|
+
if (response.status === 200) {
|
|
11584
11584
|
this._fullData = buffer;
|
|
11585
11585
|
}
|
|
11586
11586
|
return {
|
|
@@ -11605,6 +11605,22 @@ var UrlSource = class extends Source {
|
|
|
11605
11605
|
if (this._fullData) {
|
|
11606
11606
|
return this._fullData.byteLength;
|
|
11607
11607
|
}
|
|
11608
|
+
try {
|
|
11609
|
+
const headResponse = await retriedFetch(
|
|
11610
|
+
this._url,
|
|
11611
|
+
mergeObjectsDeeply(this._options.requestInit ?? {}, {
|
|
11612
|
+
method: "HEAD"
|
|
11613
|
+
}),
|
|
11614
|
+
this._options.getRetryDelay ?? (() => null)
|
|
11615
|
+
);
|
|
11616
|
+
if (headResponse.ok) {
|
|
11617
|
+
const contentLength = headResponse.headers.get("Content-Length");
|
|
11618
|
+
if (contentLength) {
|
|
11619
|
+
return parseInt(contentLength);
|
|
11620
|
+
}
|
|
11621
|
+
}
|
|
11622
|
+
} catch {
|
|
11623
|
+
}
|
|
11608
11624
|
const rangeResponse = await retriedFetch(
|
|
11609
11625
|
this._url,
|
|
11610
11626
|
mergeObjectsDeeply(this._options.requestInit ?? {}, {
|
|
@@ -11618,9 +11634,12 @@ var UrlSource = class extends Source {
|
|
|
11618
11634
|
if (contentRange) {
|
|
11619
11635
|
const match = contentRange.match(/bytes \d+-\d+\/(\d+)/);
|
|
11620
11636
|
if (match && match[1]) {
|
|
11621
|
-
return parseInt(match[1]
|
|
11637
|
+
return parseInt(match[1]);
|
|
11622
11638
|
}
|
|
11623
11639
|
}
|
|
11640
|
+
} else if (rangeResponse.status === 200) {
|
|
11641
|
+
this._fullData = await rangeResponse.arrayBuffer();
|
|
11642
|
+
return this._fullData.byteLength;
|
|
11624
11643
|
}
|
|
11625
11644
|
const { response } = await this._makeRequest();
|
|
11626
11645
|
return response.byteLength;
|
package/dist/modules/misc.js
CHANGED
|
@@ -406,12 +406,12 @@ export const retriedFetch = async (url, requestInit, getRetryDelay) => {
|
|
|
406
406
|
return await fetch(url, requestInit);
|
|
407
407
|
}
|
|
408
408
|
catch (error) {
|
|
409
|
-
console.error('Retrying failed fetch. Error:', error);
|
|
410
409
|
attempts++;
|
|
411
410
|
const retryDelayInSeconds = getRetryDelay(attempts);
|
|
412
411
|
if (retryDelayInSeconds === null) {
|
|
413
412
|
throw error;
|
|
414
413
|
}
|
|
414
|
+
console.error('Retrying failed fetch. Error:', error);
|
|
415
415
|
if (!Number.isFinite(retryDelayInSeconds) || retryDelayInSeconds < 0) {
|
|
416
416
|
throw new TypeError('Retry delay must be a non-negative finite number.');
|
|
417
417
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,8BAAsB,MAAM;IAS3B;;;OAGG;IACH,OAAO;IAIP,0DAA0D;IAC1D,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,IAAI,CAAQ;CAChE;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,MAAM;gBAI3B,MAAM,EAAE,WAAW,GAAG,UAAU;CAmB5C;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IACjC,0GAA0G;IAC1G,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACvE,2GAA2G;IAC3G,OAAO,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;;GAGG;AACH,qBAAa,YAAa,SAAQ,MAAM;gBAI3B,OAAO,EAAE,mBAAmB;CAyBxC;AAED;;;GAGG;AACH,qBAAa,UAAW,SAAQ,MAAM;gBAIzB,IAAI,EAAE,IAAI;CAqBtB;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CAC5D,CAAC;AAEF;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,MAAM;gBASnC,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,OAAO,GAAE,gBAAqB;
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,8BAAsB,MAAM;IAS3B;;;OAGG;IACH,OAAO;IAIP,0DAA0D;IAC1D,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,IAAI,CAAQ;CAChE;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,MAAM;gBAI3B,MAAM,EAAE,WAAW,GAAG,UAAU;CAmB5C;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IACjC,0GAA0G;IAC1G,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACvE,2GAA2G;IAC3G,OAAO,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;;GAGG;AACH,qBAAa,YAAa,SAAQ,MAAM;gBAI3B,OAAO,EAAE,mBAAmB;CAyBxC;AAED;;;GAGG;AACH,qBAAa,UAAW,SAAQ,MAAM;gBAIzB,IAAI,EAAE,IAAI;CAqBtB;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CAC5D,CAAC;AAEF;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,MAAM;gBASnC,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,OAAO,GAAE,gBAAqB;CAiI/B"}
|
package/dist/modules/source.js
CHANGED
|
@@ -135,7 +135,8 @@ export class UrlSource extends Source {
|
|
|
135
135
|
throw new Error(`Error fetching ${this._url}: ${response.status} ${response.statusText}`);
|
|
136
136
|
}
|
|
137
137
|
const buffer = await response.arrayBuffer();
|
|
138
|
-
if (
|
|
138
|
+
if (response.status === 200) {
|
|
139
|
+
// The server didn't return 206 Partial Content, so it's not a range response
|
|
139
140
|
this._fullData = buffer;
|
|
140
141
|
}
|
|
141
142
|
return {
|
|
@@ -162,6 +163,21 @@ export class UrlSource extends Source {
|
|
|
162
163
|
if (this._fullData) {
|
|
163
164
|
return this._fullData.byteLength;
|
|
164
165
|
}
|
|
166
|
+
// First, try a HEAD request to get the size
|
|
167
|
+
try {
|
|
168
|
+
const headResponse = await retriedFetch(this._url, mergeObjectsDeeply(this._options.requestInit ?? {}, {
|
|
169
|
+
method: 'HEAD',
|
|
170
|
+
}), this._options.getRetryDelay ?? (() => null));
|
|
171
|
+
if (headResponse.ok) {
|
|
172
|
+
const contentLength = headResponse.headers.get('Content-Length');
|
|
173
|
+
if (contentLength) {
|
|
174
|
+
return parseInt(contentLength);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// We tried
|
|
180
|
+
}
|
|
165
181
|
// Try a range request to get the Content-Range header
|
|
166
182
|
const rangeResponse = await retriedFetch(this._url, mergeObjectsDeeply(this._options.requestInit ?? {}, {
|
|
167
183
|
method: 'GET',
|
|
@@ -172,10 +188,15 @@ export class UrlSource extends Source {
|
|
|
172
188
|
if (contentRange) {
|
|
173
189
|
const match = contentRange.match(/bytes \d+-\d+\/(\d+)/);
|
|
174
190
|
if (match && match[1]) {
|
|
175
|
-
return parseInt(match[1]
|
|
191
|
+
return parseInt(match[1]);
|
|
176
192
|
}
|
|
177
193
|
}
|
|
178
194
|
}
|
|
195
|
+
else if (rangeResponse.status === 200) {
|
|
196
|
+
// The server just returned the whole thing
|
|
197
|
+
this._fullData = await rangeResponse.arrayBuffer();
|
|
198
|
+
return this._fullData.byteLength;
|
|
199
|
+
}
|
|
179
200
|
// If the range request didn't provide the size, make a full GET request
|
|
180
201
|
const { response } = await this._makeRequest();
|
|
181
202
|
return response.byteLength;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mediabunny",
|
|
3
3
|
"author": "Vanilagy",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/bundles/mediabunny.cjs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@types/dom-mediacapture-transform": "^0.1.11",
|
|
52
|
-
"@types/dom-webcodecs": "
|
|
52
|
+
"@types/dom-webcodecs": "0.1.13"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@eslint/js": "^9.22.0",
|
package/src/misc.ts
CHANGED
|
@@ -515,15 +515,15 @@ export const retriedFetch = async (
|
|
|
515
515
|
try {
|
|
516
516
|
return await fetch(url, requestInit);
|
|
517
517
|
} catch (error) {
|
|
518
|
-
console.error('Retrying failed fetch. Error:', error);
|
|
519
|
-
|
|
520
518
|
attempts++;
|
|
521
|
-
|
|
522
519
|
const retryDelayInSeconds = getRetryDelay(attempts);
|
|
520
|
+
|
|
523
521
|
if (retryDelayInSeconds === null) {
|
|
524
522
|
throw error;
|
|
525
523
|
}
|
|
526
524
|
|
|
525
|
+
console.error('Retrying failed fetch. Error:', error);
|
|
526
|
+
|
|
527
527
|
if (!Number.isFinite(retryDelayInSeconds) || retryDelayInSeconds < 0) {
|
|
528
528
|
throw new TypeError('Retry delay must be a non-negative finite number.');
|
|
529
529
|
}
|
package/src/source.ts
CHANGED
|
@@ -218,7 +218,8 @@ export class UrlSource extends Source {
|
|
|
218
218
|
|
|
219
219
|
const buffer = await response.arrayBuffer();
|
|
220
220
|
|
|
221
|
-
if (
|
|
221
|
+
if (response.status === 200) {
|
|
222
|
+
// The server didn't return 206 Partial Content, so it's not a range response
|
|
222
223
|
this._fullData = buffer;
|
|
223
224
|
}
|
|
224
225
|
|
|
@@ -252,6 +253,26 @@ export class UrlSource extends Source {
|
|
|
252
253
|
return this._fullData.byteLength;
|
|
253
254
|
}
|
|
254
255
|
|
|
256
|
+
// First, try a HEAD request to get the size
|
|
257
|
+
try {
|
|
258
|
+
const headResponse = await retriedFetch(
|
|
259
|
+
this._url,
|
|
260
|
+
mergeObjectsDeeply(this._options.requestInit ?? {}, {
|
|
261
|
+
method: 'HEAD',
|
|
262
|
+
}),
|
|
263
|
+
this._options.getRetryDelay ?? (() => null),
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
if (headResponse.ok) {
|
|
267
|
+
const contentLength = headResponse.headers.get('Content-Length');
|
|
268
|
+
if (contentLength) {
|
|
269
|
+
return parseInt(contentLength);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
} catch {
|
|
273
|
+
// We tried
|
|
274
|
+
}
|
|
275
|
+
|
|
255
276
|
// Try a range request to get the Content-Range header
|
|
256
277
|
const rangeResponse = await retriedFetch(
|
|
257
278
|
this._url,
|
|
@@ -267,9 +288,13 @@ export class UrlSource extends Source {
|
|
|
267
288
|
if (contentRange) {
|
|
268
289
|
const match = contentRange.match(/bytes \d+-\d+\/(\d+)/);
|
|
269
290
|
if (match && match[1]) {
|
|
270
|
-
return parseInt(match[1]
|
|
291
|
+
return parseInt(match[1]);
|
|
271
292
|
}
|
|
272
293
|
}
|
|
294
|
+
} else if (rangeResponse.status === 200) {
|
|
295
|
+
// The server just returned the whole thing
|
|
296
|
+
this._fullData = await rangeResponse.arrayBuffer();
|
|
297
|
+
return this._fullData.byteLength;
|
|
273
298
|
}
|
|
274
299
|
|
|
275
300
|
// If the range request didn't provide the size, make a full GET request
|