merfix 0.1.55 → 0.1.56

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/merfix.js CHANGED
@@ -1,9 +1,5 @@
1
1
  let wasm;
2
2
 
3
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
4
-
5
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
6
-
7
3
  let cachedUint8ArrayMemory0 = null;
8
4
 
9
5
  function getUint8ArrayMemory0() {
@@ -13,9 +9,25 @@ function getUint8ArrayMemory0() {
13
9
  return cachedUint8ArrayMemory0;
14
10
  }
15
11
 
12
+ let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
13
+
14
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
15
+
16
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
17
+ let numBytesDecoded = 0;
18
+ function decodeText(ptr, len) {
19
+ numBytesDecoded += len;
20
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
21
+ cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
22
+ cachedTextDecoder.decode();
23
+ numBytesDecoded = len;
24
+ }
25
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
26
+ }
27
+
16
28
  function getStringFromWasm0(ptr, len) {
17
29
  ptr = ptr >>> 0;
18
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
30
+ return decodeText(ptr, len);
19
31
  }
20
32
 
21
33
  function getArrayU8FromWasm0(ptr, len) {
@@ -266,6 +278,8 @@ export class ExifRemovalResult {
266
278
  }
267
279
  }
268
280
 
281
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
282
+
269
283
  async function __wbg_load(module, imports) {
270
284
  if (typeof Response === 'function' && module instanceof Response) {
271
285
  if (typeof WebAssembly.instantiateStreaming === 'function') {
@@ -273,7 +287,9 @@ async function __wbg_load(module, imports) {
273
287
  return await WebAssembly.instantiateStreaming(module, imports);
274
288
 
275
289
  } catch (e) {
276
- if (module.headers.get('Content-Type') != 'application/wasm') {
290
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
291
+
292
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
277
293
  console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
278
294
 
279
295
  } else {
package/merfix_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "merfix",
3
3
  "type": "module",
4
4
  "description": "Utility to remove EXIF metadata from images from browser",
5
- "version": "0.1.55",
5
+ "version": "0.1.56",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",