exifreader 4.48.1 → 4.50.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.
@@ -4,6 +4,11 @@
4
4
 
5
5
  import Constants from './constants.js';
6
6
 
7
+ // The order the main Exif block reads them in. It is the key order of expanded
8
+ // output, and in flat output later groups win a key clash, so Exif wins over
9
+ // all of them but an ApplicationNotes XMP packet.
10
+ export const EXIF_CARRIED_GROUP_ORDER = ['iptc', 'xmp', 'photoshop', 'icc', 'makerNotes'];
11
+
7
12
  export function buildTagsFromMergeSteps({
8
13
  mergeSteps,
9
14
  deferredResults,
@@ -117,22 +122,25 @@ export function applyMergeStep({
117
122
  }
118
123
 
119
124
  if (Constants.USE_JXL && step.type === 'mergeBrobExifDeferred') {
120
- const resolvedReadTags = deferredResults[step.deferredKey];
121
- if (!resolvedReadTags || Object.keys(resolvedReadTags).length === 0) {
125
+ const resolved = deferredResults[step.deferredKey];
126
+ if (!resolved) {
122
127
  return tags;
123
128
  }
124
- const parsedExifTags =
125
- deps.filterTagsForParse('exif', resolvedReadTags, tagFilter);
126
- parsedGroups.exif = !parsedGroups.exif ? parsedExifTags : deps.objectAssign({}, parsedGroups.exif, parsedExifTags);
127
-
128
- if (!tagFilter.shouldReturnGroup('exif')) {
129
+ addEmbeddedExifThumbnail(embeddedExifThumbnails, resolved.thumbnail);
130
+ if (Object.keys(resolved.exifTags).length === 0) {
129
131
  return tags;
130
132
  }
131
133
 
132
- const returnedTags =
133
- deps.filterTagsForReturn('exif', parsedExifTags, tagFilter);
134
-
135
- return mergeAssignGroup(tags, 'exif', returnedTags, expanded, deps);
134
+ return addExifAndCarriedGroupsToTagsAndGroups({
135
+ exifTags: resolved.exifTags,
136
+ carriedGroups: resolved.carriedGroups,
137
+ parsedGroups,
138
+ expanded,
139
+ tagFilter,
140
+ tags,
141
+ deps,
142
+ merge: createCopyingMerge(deps),
143
+ });
136
144
  }
137
145
 
138
146
  if (Constants.USE_JXL && step.type === 'mergeBrobXmpDeferred') {
@@ -202,6 +210,7 @@ export function applyMergeStep({
202
210
  return addPngTextReadTagsToTagsAndGroups({
203
211
  readTags: step.readTags,
204
212
  embeddedExifTags: step.embeddedExifTags,
213
+ exifCarriedGroups: step.exifCarriedGroups,
205
214
  embeddedIptcTags: step.embeddedIptcTags,
206
215
  parsedGroups,
207
216
  expanded,
@@ -221,6 +230,7 @@ export function applyMergeStep({
221
230
  tags = addPngTextReadTagsToTagsAndGroups({
222
231
  readTags: entry.readTags || {},
223
232
  embeddedExifTags: entry.embeddedExifTags,
233
+ exifCarriedGroups: entry.exifCarriedGroups,
224
234
  embeddedIptcTags: entry.embeddedIptcTags,
225
235
  parsedGroups,
226
236
  expanded,
@@ -378,7 +388,7 @@ function hasImage(thumbnail) {
378
388
  }
379
389
 
380
390
  function getFirstEmbeddedExifThumbnailWithImage(embeddedExifThumbnails) {
381
- if (!(Constants.USE_PNG && Constants.USE_EXIF && Constants.USE_THUMBNAIL)) {
391
+ if (!((Constants.USE_PNG || Constants.USE_JXL) && Constants.USE_EXIF && Constants.USE_THUMBNAIL)) {
382
392
  return undefined;
383
393
  }
384
394
  return embeddedExifThumbnails.filter(hasImage)[0];
@@ -424,6 +434,7 @@ export function mergeMergeGroup(tags, groupKey, returnedTags, expanded, deps) {
424
434
  export function addPngTextReadTagsToTagsAndGroups({
425
435
  readTags,
426
436
  embeddedExifTags,
437
+ exifCarriedGroups,
427
438
  embeddedIptcTags,
428
439
  parsedGroups,
429
440
  expanded,
@@ -433,22 +444,16 @@ export function addPngTextReadTagsToTagsAndGroups({
433
444
  merge = createCopyingMerge(deps),
434
445
  }) {
435
446
  if (embeddedExifTags) {
436
- const parsedEmbeddedExifTags =
437
- deps.filterTagsForParse('exif', embeddedExifTags, tagFilter);
438
- merge.group(parsedGroups, 'exif', parsedEmbeddedExifTags);
439
-
440
- if (tagFilter.shouldReturnGroup('exif')) {
441
- const returnedEmbeddedExifTags = deps.filterTagsForReturn(
442
- 'exif',
443
- parsedEmbeddedExifTags,
444
- tagFilter
445
- );
446
- if (expanded) {
447
- merge.group(tags, 'exif', returnedEmbeddedExifTags);
448
- } else {
449
- tags = merge.topLevel(tags, returnedEmbeddedExifTags);
450
- }
451
- }
447
+ tags = addExifAndCarriedGroupsToTagsAndGroups({
448
+ exifTags: embeddedExifTags,
449
+ carriedGroups: exifCarriedGroups || {},
450
+ parsedGroups,
451
+ expanded,
452
+ tagFilter,
453
+ tags,
454
+ deps,
455
+ merge,
456
+ });
452
457
  }
453
458
 
454
459
  if (embeddedIptcTags) {
@@ -493,6 +498,79 @@ export function addPngTextReadTagsToTagsAndGroups({
493
498
  return tags;
494
499
  }
495
500
 
501
+ /**
502
+ * Merges one Exif block and the groups it carries in the order the main Exif
503
+ * block merges them: the carried groups, then Exif, then in flat output the
504
+ * ApplicationNotes XMP. The carried groups arrive parsed and are not filtered
505
+ * for parse again.
506
+ *
507
+ * @returns {object} The tags, which flat output replaces rather than mutates.
508
+ */
509
+ export function addExifAndCarriedGroupsToTagsAndGroups({
510
+ exifTags,
511
+ carriedGroups,
512
+ parsedGroups,
513
+ expanded,
514
+ tagFilter,
515
+ tags,
516
+ deps,
517
+ merge,
518
+ }) {
519
+ let flatXmpGroup = undefined;
520
+
521
+ for (let i = 0; i < EXIF_CARRIED_GROUP_ORDER.length; i++) {
522
+ const groupKey = EXIF_CARRIED_GROUP_ORDER[i];
523
+ const group = carriedGroups[groupKey];
524
+ if (group === undefined) {
525
+ continue;
526
+ }
527
+ if (groupKey === 'xmp' && !expanded) {
528
+ flatXmpGroup = group;
529
+ continue;
530
+ }
531
+ tags = addCarriedGroup(groupKey, group);
532
+ }
533
+
534
+ if (exifTags) {
535
+ const parsedExifTags = deps.filterTagsForParse('exif', exifTags, tagFilter);
536
+ merge.group(parsedGroups, 'exif', parsedExifTags);
537
+
538
+ if (tagFilter.shouldReturnGroup('exif')) {
539
+ const returnedExifTags = deps.filterTagsForReturn('exif', parsedExifTags, tagFilter);
540
+ if (expanded) {
541
+ merge.group(tags, 'exif', returnedExifTags);
542
+ } else {
543
+ tags = merge.topLevel(tags, returnedExifTags);
544
+ }
545
+ }
546
+ }
547
+
548
+ if (flatXmpGroup !== undefined) {
549
+ tags = addCarriedGroup('xmp', flatXmpGroup, true);
550
+ }
551
+
552
+ return tags;
553
+
554
+ function addCarriedGroup(groupKey, group, isFlatXmp) {
555
+ merge.group(parsedGroups, groupKey, group);
556
+ if (!tagFilter.shouldReturnGroup(groupKey)) {
557
+ return tags;
558
+ }
559
+ const returnedTags = deps.filterTagsForReturn(groupKey, group, tagFilter);
560
+ if (expanded) {
561
+ merge.group(tags, groupKey, returnedTags);
562
+ return tags;
563
+ }
564
+ return merge.topLevel(tags, isFlatXmp ? getXmpTagsWithoutRaw(returnedTags) : returnedTags);
565
+ }
566
+
567
+ function getXmpTagsWithoutRaw(xmpTags) {
568
+ const xmpTagsWithoutRaw = deps.objectAssign({}, xmpTags);
569
+ delete xmpTagsWithoutRaw._raw;
570
+ return xmpTagsWithoutRaw;
571
+ }
572
+ }
573
+
496
574
  function createCopyingMerge(deps) {
497
575
  return {
498
576
  group(holder, key, source) {
@@ -0,0 +1,84 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ /* global globalThis, __non_webpack_require__ */
6
+
7
+ export default {
8
+ builtin,
9
+ optionalPackage
10
+ };
11
+
12
+ /**
13
+ * Loads a Node builtin module such as `fs`, `http` or `https`.
14
+ *
15
+ * @param {string} name
16
+ * @returns {Object|undefined} The module, or undefined where none is reachable
17
+ * (browsers, workers).
18
+ */
19
+ function builtin(name) {
20
+ return firstLoaded(name, [webpackRequire, getBuiltinModule, mainModuleRequire]);
21
+ }
22
+
23
+ /**
24
+ * Loads an installed package through the literal require that webpack emits,
25
+ * which Node and bundlers resolve from the UMD. The ES module source outside
26
+ * webpack gets none: programs pass the domParser option instead.
27
+ *
28
+ * @param {string} name
29
+ * @returns {Object|undefined} The package, or undefined where none is reachable.
30
+ */
31
+ function optionalPackage(name) {
32
+ return firstLoaded(name, [webpackRequire]);
33
+ }
34
+
35
+ // A loader throws where its mechanism is missing (no process, no
36
+ // getBuiltinModule, no mainModule), which moves on to the next one. process is
37
+ // never named as a free variable: Parcel 2 and webpack 4 would then bundle a
38
+ // process polyfill into browser builds of the source.
39
+ function firstLoaded(name, loaders) {
40
+ for (let i = 0; i < loaders.length; i++) {
41
+ try {
42
+ return loaders[i](name);
43
+ } catch (error) {
44
+ // Try the next loader.
45
+ }
46
+ }
47
+ return undefined;
48
+ }
49
+
50
+ // Literal names make webpack emit require('fs') and so on, which bundlers and
51
+ // file tracers follow. No typeof guard: webpack may not rewrite the identifier there.
52
+ // A try in this function makes bundlers treat fs and @xmldom/xmldom as optional.
53
+ function webpackRequire(name) {
54
+ switch (name) {
55
+ case 'fs':
56
+ // eslint-disable-next-line no-useless-catch
57
+ try {
58
+ return __non_webpack_require__('fs');
59
+ } catch (error) {
60
+ throw error;
61
+ }
62
+ case 'http':
63
+ return __non_webpack_require__('http');
64
+ case 'https':
65
+ return __non_webpack_require__('https');
66
+ case '@xmldom/xmldom':
67
+ // eslint-disable-next-line no-useless-catch
68
+ try {
69
+ return __non_webpack_require__('@xmldom/xmldom');
70
+ } catch (error) {
71
+ throw error;
72
+ }
73
+ default:
74
+ throw new Error(`No webpack require for ${name}.`);
75
+ }
76
+ }
77
+
78
+ function getBuiltinModule(name) {
79
+ return globalThis.process.getBuiltinModule(name);
80
+ }
81
+
82
+ function mainModuleRequire(name) {
83
+ return globalThis.process.mainModule.require(name);
84
+ }
@@ -11,7 +11,7 @@ import Tags from './tags.js';
11
11
  import IptcTags from './iptc-tags.js';
12
12
  import Constants from './constants.js';
13
13
  import {NOOP_TAG_FILTER} from './tag-filter.js';
14
- import {addDecompressedValueAllowance, addDecompressedIptcAllowance} from './tags-helpers.js';
14
+ import {addDecompressedValueAllowance, addDecompressedIptcAllowance, takeEmbeddedExifThumbnail} from './tags-helpers.js';
15
15
 
16
16
  export default {
17
17
  read
@@ -29,6 +29,7 @@ const MAX_COMPRESSED_TEXT_CHUNKS = 255;
29
29
  const MAX_DECOMPRESSIONS_IN_FLIGHT = 4;
30
30
  // PNG spec: a keyword is 1-79 bytes.
31
31
  const MAX_KEYWORD_LENGTH = 79;
32
+ const IPTC_PROFILE_NAME = 'raw profile type iptc';
32
33
  // Our own bound: BCP 47 sets no maximum, but real tags are far shorter.
33
34
  const MAX_LANGUAGE_TAG_LENGTH = 79;
34
35
 
@@ -38,14 +39,21 @@ const MAX_LANGUAGE_TAG_LENGTH = 79;
38
39
  * decoded Exif raw profile, its thumbnail IFD tags and the TIFF header offset;
39
40
  * returns the thumbnail tags, with `image` set when the thumbnail was read.
40
41
  * No thumbnail is returned when it is not passed.
41
- * @returns {{readTags: object, embeddedExifTags: object|undefined, embeddedIptcTags: object|undefined, embeddedExifThumbnail: object|undefined, readTagsPromise: Promise<object[]>|undefined}}
42
- * `readTags`, the two embedded groups and `embeddedExifThumbnail` come from
43
- * uncompressed chunks and are ready at once; the embedded groups are undefined
44
- * when no uncompressed raw profile was parsed, and `embeddedExifThumbnail` is
45
- * the first thumbnail with an image. `readTagsPromise` resolves to one result
46
- * per compressed chunk, in chunk order, each with its own
47
- * `embeddedExifThumbnail` when it has one and no uncompressed chunk had one,
48
- * and is undefined when none is read.
42
+ * @param {function(DataView, object, number, number, object, {decompressed: boolean, hasIptcBlock: boolean}): object} [readCarriedGroups]
43
+ * Called with a decoded Exif raw profile, the Exif tags read from it, the TIFF
44
+ * header offset, the byte order, the value budget and where the profile came
45
+ * from: `decompressed` when the chunk was compressed, `hasIptcBlock` when the
46
+ * file has a `Raw profile type iptc` chunk. Returns the parsed groups the Exif
47
+ * carries, keyed by group name. No groups are read when it is not passed.
48
+ * @returns {{readTags: object, embeddedExifTags: object|undefined, embeddedIptcTags: object|undefined, embeddedExifThumbnail: object|undefined, exifCarriedGroups: object|undefined, readTagsPromise: Promise<object[]>|undefined}}
49
+ * `readTags`, the two embedded groups, `exifCarriedGroups` and
50
+ * `embeddedExifThumbnail` come from uncompressed chunks and are ready at
51
+ * once; the embedded groups and `exifCarriedGroups` are undefined when no
52
+ * uncompressed raw profile was parsed, and `embeddedExifThumbnail` is the
53
+ * first thumbnail with an image. `readTagsPromise` resolves to one result per
54
+ * compressed chunk, in chunk order, each with its own `exifCarriedGroups`, and
55
+ * its own `embeddedExifThumbnail` when it has one and no uncompressed chunk
56
+ * had one, and is undefined when none is read.
49
57
  */
50
58
  function read(
51
59
  dataView,
@@ -56,12 +64,15 @@ function read(
56
64
  tagFilter = NOOP_TAG_FILTER,
57
65
  decompressConfig,
58
66
  valueBudget,
59
- getThumbnail
67
+ getThumbnail,
68
+ readCarriedGroups
60
69
  ) {
61
70
  const tags = {};
62
71
  let embeddedExifTags;
63
72
  let embeddedIptcTags;
64
73
  let embeddedExifThumbnail;
74
+ let exifCarriedGroups;
75
+ const uncompressedRawProfiles = [];
65
76
  const compressedChunks = [];
66
77
 
67
78
  for (let i = 0; i < pngTextChunks.length; i++) {
@@ -75,23 +86,7 @@ function read(
75
86
  if (textChunk.compressionMethod === COMPRESSION_METHOD_NONE) {
76
87
  const tag = getUncompressedTag(textChunk);
77
88
  if (isRawProfileTag(tag)) {
78
- const rawProfileTags = getTagsFromTextTag(
79
- tag,
80
- includeUnknown,
81
- computed,
82
- tagFilter,
83
- valueBudget,
84
- embeddedExifThumbnail ? undefined : getThumbnail
85
- );
86
- if (rawProfileTags.embeddedExifTags) {
87
- embeddedExifTags = objectAssign(embeddedExifTags || {}, rawProfileTags.embeddedExifTags);
88
- }
89
- if (rawProfileTags.embeddedExifThumbnail) {
90
- embeddedExifThumbnail = rawProfileTags.embeddedExifThumbnail;
91
- }
92
- if (rawProfileTags.embeddedIptcTags) {
93
- embeddedIptcTags = objectAssign(embeddedIptcTags || {}, rawProfileTags.embeddedIptcTags);
94
- }
89
+ uncompressedRawProfiles.push(tag);
95
90
  } else if (tag.name && tagFilter.shouldParseGroup('png')) {
96
91
  setProperty(tags, getTagKey(tag.name), {
97
92
  value: tag.value,
@@ -103,6 +98,35 @@ function read(
103
98
  }
104
99
  }
105
100
 
101
+ const hasIptcProfile = uncompressedRawProfiles.some((tag) => isIptcGroupTag(tag.name, tag.value))
102
+ || compressedChunks.some(isCompressedIptcProfile);
103
+
104
+ for (let i = 0; i < uncompressedRawProfiles.length; i++) {
105
+ const rawProfileTags = getTagsFromTextTag(
106
+ uncompressedRawProfiles[i],
107
+ includeUnknown,
108
+ computed,
109
+ tagFilter,
110
+ valueBudget,
111
+ embeddedExifThumbnail ? undefined : getThumbnail,
112
+ readCarriedGroups,
113
+ false,
114
+ hasIptcProfile
115
+ );
116
+ if (rawProfileTags.embeddedExifTags) {
117
+ embeddedExifTags = objectAssign(embeddedExifTags || {}, rawProfileTags.embeddedExifTags);
118
+ }
119
+ if (rawProfileTags.exifCarriedGroups) {
120
+ exifCarriedGroups = mergeCarriedGroups(exifCarriedGroups || {}, rawProfileTags.exifCarriedGroups);
121
+ }
122
+ if (rawProfileTags.embeddedExifThumbnail) {
123
+ embeddedExifThumbnail = rawProfileTags.embeddedExifThumbnail;
124
+ }
125
+ if (rawProfileTags.embeddedIptcTags) {
126
+ embeddedIptcTags = objectAssign(embeddedIptcTags || {}, rawProfileTags.embeddedIptcTags);
127
+ }
128
+ }
129
+
106
130
  const compressedThumbnailReader = embeddedExifThumbnail ? undefined : getThumbnail;
107
131
  const decompressionTasks = compressedChunks.map((textChunk) => () => decompressTextChunk(textChunk, decompressConfig)
108
132
  .then((tag) => getTagsFromTextTag(
@@ -112,7 +136,9 @@ function read(
112
136
  tagFilter,
113
137
  valueBudget,
114
138
  compressedThumbnailReader,
115
- true
139
+ readCarriedGroups,
140
+ true,
141
+ hasIptcProfile
116
142
  )));
117
143
 
118
144
  return {
@@ -120,10 +146,24 @@ function read(
120
146
  embeddedExifTags,
121
147
  embeddedIptcTags,
122
148
  embeddedExifThumbnail,
149
+ exifCarriedGroups,
123
150
  readTagsPromise: decompressionTasks.length > 0 ? runTasksInOrder(decompressionTasks, MAX_DECOMPRESSIONS_IN_FLIGHT) : undefined
124
151
  };
125
152
  }
126
153
 
154
+ // A compressed profile counts before its value can be checked.
155
+ function isCompressedIptcProfile({type, langChars, keywordChars}) {
156
+ return getName(type, langChars, keywordChars).toLowerCase() === IPTC_PROFILE_NAME;
157
+ }
158
+
159
+ function mergeCarriedGroups(target, source) {
160
+ const groupKeys = Object.keys(source);
161
+ for (let i = 0; i < groupKeys.length; i++) {
162
+ target[groupKeys[i]] = objectAssign(target[groupKeys[i]] || {}, source[groupKeys[i]]);
163
+ }
164
+ return target;
165
+ }
166
+
127
167
  function parseTextChunk(dataView, offset, length, type) {
128
168
  const keywordChars = [];
129
169
  const langChars = [];
@@ -176,7 +216,7 @@ function isRawProfileTag({name, value}) {
176
216
  return isExifGroupTag(name, value) || isIptcGroupTag(name, value);
177
217
  }
178
218
 
179
- function getTagsFromTextTag({name, value, description}, includeUnknown, computed, tagFilter, valueBudget, getThumbnail, isDecompressed) {
219
+ function getTagsFromTextTag({name, value, description}, includeUnknown, computed, tagFilter, valueBudget, getThumbnail, readCarriedGroups, isDecompressed, hasIptcProfile) {
180
220
  try {
181
221
  if (Constants.USE_EXIF && isExifGroupTag(name, value)) {
182
222
  if (!tagFilter.shouldParseGroup('exif')) {
@@ -186,18 +226,33 @@ function getTagsFromTextTag({name, value, description}, includeUnknown, computed
186
226
  if (isDecompressed) {
187
227
  addDecompressedValueAllowance(valueBudget, exifDataView.byteLength);
188
228
  }
189
- const embeddedExifTags = Tags.read(
229
+ const {tags: embeddedExifTags, byteOrder} = Tags.read(
190
230
  exifDataView,
191
231
  EXIF_OFFSET,
192
232
  includeUnknown,
193
233
  computed,
194
234
  tagFilter,
195
235
  valueBudget
196
- ).tags;
236
+ );
237
+ const result = {embeddedExifTags};
238
+ if (readCarriedGroups) {
239
+ result.exifCarriedGroups = readCarriedGroups(
240
+ exifDataView,
241
+ embeddedExifTags,
242
+ EXIF_OFFSET,
243
+ byteOrder,
244
+ valueBudget,
245
+ {decompressed: isDecompressed, hasIptcBlock: hasIptcProfile}
246
+ );
247
+ }
197
248
  if (embeddedExifTags['MakerNote']) {
198
249
  delete embeddedExifTags['MakerNote'].__offset;
199
250
  }
200
- return withEmbeddedExifThumbnail({embeddedExifTags}, exifDataView, getThumbnail);
251
+ const thumbnail = takeEmbeddedExifThumbnail(embeddedExifTags, exifDataView, EXIF_OFFSET, getThumbnail);
252
+ if (thumbnail) {
253
+ result.embeddedExifThumbnail = thumbnail;
254
+ }
255
+ return result;
201
256
  } else if (Constants.USE_IPTC && isIptcGroupTag(name, value)) {
202
257
  if (!tagFilter.shouldParseGroup('iptc')) {
203
258
  return {};
@@ -232,22 +287,6 @@ function getTagsFromTextTag({name, value, description}, includeUnknown, computed
232
287
  return {};
233
288
  }
234
289
 
235
- function withEmbeddedExifThumbnail(result, exifDataView, getThumbnail) {
236
- const thumbnailIfdTags = result.embeddedExifTags.Thumbnail;
237
- if (!thumbnailIfdTags) {
238
- return result;
239
- }
240
- delete result.embeddedExifTags.Thumbnail;
241
-
242
- if (getThumbnail) {
243
- const thumbnail = getThumbnail(exifDataView, thumbnailIfdTags, EXIF_OFFSET);
244
- if (thumbnail.image) {
245
- result.embeddedExifThumbnail = thumbnail;
246
- }
247
- }
248
- return result;
249
- }
250
-
251
290
  function decompressTextChunk({type, keywordChars, langChars, compressionMethod, valueChars}, decompressConfig) {
252
291
  if (valueChars === undefined) {
253
292
  return Promise.resolve(constructPlaceholderTag(type, langChars, keywordChars));
@@ -354,7 +393,7 @@ function isExifGroupTag(name, value) {
354
393
  }
355
394
 
356
395
  function isIptcGroupTag(name, value) {
357
- return name.toLowerCase() === 'raw profile type iptc' && value.substring(1, 5) === 'iptc';
396
+ return name.toLowerCase() === IPTC_PROFILE_NAME && value.substring(1, 5) === 'iptc';
358
397
  }
359
398
 
360
399
  function decodeRawData(value) {
@@ -3,7 +3,7 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import TextDecoder from './text-decoder.js';
6
- import {decodeUtf8ByteString, tryDecodeUtf8ByteString} from './utils.js';
6
+ import {decodeUtf8ByteString, getByteString, tryDecodeUtf8ByteString} from './utils.js';
7
7
 
8
8
  const TAG_HEADER_SIZE = 5;
9
9
 
@@ -42,7 +42,7 @@ function decode(encoding, tagValue) {
42
42
  }
43
43
  }
44
44
 
45
- const stringValue = tagValue.map((charCode) => String.fromCharCode(charCode)).join('');
45
+ const stringValue = getByteString(tagValue);
46
46
  const decoded = tryDecodeUtf8ByteString(stringValue);
47
47
  if (decoded !== undefined) {
48
48
  return decoded;
@@ -65,5 +65,5 @@ function decodeWindows1252(tagValue) {
65
65
  const mapped = WINDOWS_1252_C1_MAP[byte];
66
66
  codePoints[i] = mapped !== undefined ? mapped : byte;
67
67
  }
68
- return String.fromCharCode.apply(null, codePoints);
68
+ return getByteString(codePoints);
69
69
  }