exifreader 4.37.0 → 4.38.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/src/tags.js CHANGED
@@ -26,11 +26,15 @@ function read(dataView, tiffHeaderOffset, includeUnknown, computed = false, tagF
26
26
  }
27
27
 
28
28
  function read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter) {
29
+ const ifdOffset = get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder);
30
+ if (ifdOffset === undefined) {
31
+ return {};
32
+ }
29
33
  return readIfd(
30
34
  dataView,
31
35
  IFD_TYPE_0TH,
32
36
  tiffHeaderOffset,
33
- get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder),
37
+ ifdOffset,
34
38
  byteOrder,
35
39
  includeUnknown,
36
40
  computed,
package/src/utils.js CHANGED
@@ -149,8 +149,29 @@ export function strRepeat(string, num) {
149
149
 
150
150
  export const COMPRESSION_METHOD_NONE = undefined;
151
151
  export const COMPRESSION_METHOD_DEFLATE = 0;
152
+ export const COMPRESSION_METHOD_BROTLI = 'brotli';
153
+
154
+ export function decompress(dataView, compressionMethod, encoding, returnType = 'string', decompressConfig) {
155
+ if (decompressConfig && compressionMethod !== COMPRESSION_METHOD_NONE) {
156
+ const decompressType = compressionMethod === COMPRESSION_METHOD_DEFLATE ? 'deflate' : 'brotli';
157
+ const customFn = decompressConfig[decompressType];
158
+ if (typeof customFn === 'function') {
159
+ const uint8 = new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength);
160
+ return Promise.resolve(customFn(uint8)).then((result) => {
161
+ if (returnType === 'dataview') {
162
+ if (result instanceof DataView) {
163
+ return result;
164
+ }
165
+ if (result instanceof ArrayBuffer) {
166
+ return new DataView(result);
167
+ }
168
+ return new DataView(result.buffer, result.byteOffset, result.byteLength);
169
+ }
170
+ return new TextDecoder(encoding).decode(result);
171
+ });
172
+ }
173
+ }
152
174
 
153
- export function decompress(dataView, compressionMethod, encoding, returnType = 'string') {
154
175
  if (compressionMethod === COMPRESSION_METHOD_DEFLATE) {
155
176
  if (typeof DecompressionStream === 'function') {
156
177
  const decompressionStream = new DecompressionStream('deflate');
@@ -162,6 +183,24 @@ export function decompress(dataView, compressionMethod, encoding, returnType = '
162
183
  .then((buffer) => new TextDecoder(encoding).decode(buffer));
163
184
  }
164
185
  }
186
+
187
+ if (compressionMethod === COMPRESSION_METHOD_BROTLI) {
188
+ if (typeof DecompressionStream === 'function') {
189
+ try {
190
+ const decompressionStream = new DecompressionStream('brotli');
191
+ const decompressedStream = new Blob([dataView]).stream().pipeThrough(decompressionStream);
192
+ if (returnType === 'dataview') {
193
+ return new Response(decompressedStream).arrayBuffer().then((arrayBuffer) => new DataView(arrayBuffer));
194
+ }
195
+ return new Response(decompressedStream).arrayBuffer()
196
+ .then((buffer) => new TextDecoder(encoding).decode(buffer));
197
+ } catch (_error) {
198
+ // brotli not supported by this DecompressionStream implementation
199
+ }
200
+ }
201
+ return Promise.reject('Brotli decompression is not supported in this environment. Pass in a brotli decompression function via the decompress option.');
202
+ }
203
+
165
204
  if (compressionMethod !== undefined) {
166
205
  return Promise.reject(`Unknown compression method ${compressionMethod}.`);
167
206
  }
package/webpack.config.js CHANGED
@@ -81,7 +81,7 @@ module.exports = {
81
81
  }
82
82
  },
83
83
  {
84
- test: /[/\\](exif-reader|image-header-?(tiff|jpeg|png|heic|avif|iso-bmff|webp|gif)?|tags|tag-names|tags-helpers|png-text-tags)\.js$/,
84
+ test: /[/\\](exif-reader|image-header-?(tiff|jpeg|png|heic|avif|jxl|iso-bmff|webp|gif)?|tags|tag-names|tags-helpers|png-text-tags)\.js$/,
85
85
  loader: 'string-replace-loader',
86
86
  options: {
87
87
  multiple: getConstantReplacements(includedModules)
@@ -109,6 +109,7 @@ function parseConfig({include: includesConfig, exclude: excludesConfig}) {
109
109
  'png',
110
110
  'heic',
111
111
  'avif',
112
+ 'jxl',
112
113
  'webp',
113
114
  'gif'
114
115
  ];