@syncfusion/ej2-pdf 25.1.40 → 25.1.42

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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * filename: index.d.ts
3
- * version : 25.1.40
3
+ * version : 25.1.42
4
4
  * Copyright Syncfusion Inc. 2001 - 2023. All rights reserved.
5
5
  * Use of this code is subject to the terms of our license.
6
6
  * A copy of the current license can be obtained at any time by e-mailing
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "_from": "@syncfusion/ej2-pdf@*",
3
- "_id": "@syncfusion/ej2-pdf@25.1.39",
3
+ "_id": "@syncfusion/ej2-pdf@25.1.41",
4
4
  "_inBundle": false,
5
- "_integrity": "sha512-pWE0zlFyKavaIdUTvXidwDuQ3V8v58EB5Vgp+sqfyF+XyBoes9xjzKAsS7lKfnjJ+69lmjP6+cc6hnXfp5lsxg==",
5
+ "_integrity": "sha512-ttbsp4Ls6xMF9tP8haSvhzDK1ANItk+rY2lsf6yMeH3aGxFK4uRGvqZoFQE/sHIPEbPbRmGjLltCaHLXROoW2Q==",
6
6
  "_location": "/@syncfusion/ej2-pdf",
7
7
  "_phantomChildren": {},
8
8
  "_requested": {
@@ -21,8 +21,8 @@
21
21
  "/@syncfusion/ej2",
22
22
  "/@syncfusion/ej2-pdfviewer"
23
23
  ],
24
- "_resolved": "https://nexus.syncfusioninternal.com/repository/ej2-hotfix-new/@syncfusion/ej2-pdf/-/ej2-pdf-25.1.39.tgz",
25
- "_shasum": "5a2d3f5d6c5b9c74f92db621290da632cc3682c0",
24
+ "_resolved": "https://nexus.syncfusioninternal.com/repository/ej2-hotfix-new/@syncfusion/ej2-pdf/-/ej2-pdf-25.1.41.tgz",
25
+ "_shasum": "28e55ffd7009915939f7dcbe4569b074273d6e0b",
26
26
  "_spec": "@syncfusion/ej2-pdf@*",
27
27
  "_where": "/jenkins/workspace/elease-automation_release_25.1.1/packages/included",
28
28
  "author": {
@@ -55,7 +55,7 @@
55
55
  "url": "https://github.com/syncfusion/ej2-javascript-ui-controls/tree/master/controls/pdf"
56
56
  },
57
57
  "typings": "index.d.ts",
58
- "version": "25.1.40",
58
+ "version": "25.1.42",
59
59
  "sideEffects": false,
60
60
  "homepage": "https://www.syncfusion.com/javascript-ui-controls"
61
61
  }
@@ -5,6 +5,7 @@ import { _PdfDictionary } from './../pdf-primitives';
5
5
  import { _PdfContentStream } from './../base-stream';
6
6
  export declare class _JsonDocument extends _ExportHelper {
7
7
  _isImport: boolean;
8
+ _isColorSpace: boolean;
8
9
  constructor(fileName?: string);
9
10
  _exportAnnotations(document: PdfDocument): Uint8Array;
10
11
  _exportFormFields(document: PdfDocument): Uint8Array;
@@ -12,7 +12,7 @@ var __extends = (this && this.__extends) || (function () {
12
12
  };
13
13
  })();
14
14
  import { _ExportHelper } from './xfdf-document';
15
- import { _stringToAnnotationFlags, _convertToColor, _encode, _byteArrayToHexString, _stringToBytes, _annotationFlagsToString, _convertStringToBytes, _bytesToString, _hexStringToByteArray, _decode } from './../utils';
15
+ import { _stringToAnnotationFlags, _convertToColor, _encode, _byteArrayToHexString, _stringToBytes, _annotationFlagsToString, _bytesToString, _hexStringToByteArray, _decode } from './../utils';
16
16
  import { _PdfDictionary, _PdfName, _PdfReference } from './../pdf-primitives';
17
17
  import { _PdfBaseStream, _PdfContentStream, _PdfStream } from './../base-stream';
18
18
  import { PdfAnnotationFlag } from './../enumerator';
@@ -21,6 +21,7 @@ var _JsonDocument = /** @class */ (function (_super) {
21
21
  function _JsonDocument(fileName) {
22
22
  var _this = _super.call(this) || this;
23
23
  _this._isImport = false;
24
+ _this._isColorSpace = false;
24
25
  if (fileName !== null && typeof fileName !== 'undefined') {
25
26
  _this._fileName = fileName;
26
27
  }
@@ -68,9 +69,7 @@ var _JsonDocument = /** @class */ (function (_super) {
68
69
  if (typeof value === 'string' || (Array.isArray(value) && value.length === 1)) {
69
70
  value = _this._getValidString(typeof value === 'string' ? value : value[0]);
70
71
  _this._jsonData.push(_this._doubleQuotes, _this._colon, _this._doubleQuotes);
71
- for (var i = 0; i < value.length; i++) {
72
- _this._jsonData.push(value.charCodeAt(i));
73
- }
72
+ _this._jsonData = _stringToBytes(value, true, false, _this._jsonData);
74
73
  _this._jsonData.push(_this._doubleQuotes);
75
74
  }
76
75
  else {
@@ -103,7 +102,7 @@ var _JsonDocument = /** @class */ (function (_super) {
103
102
  var page = document.getPage(i);
104
103
  if (page && page.annotations.count > 0) {
105
104
  this._jsonData.push(i !== 0 && isAnnotationAdded ? this._comma : this._space, this._doubleQuotes);
106
- var pageNumber = _convertStringToBytes(i.toString(), []);
105
+ var pageNumber = _stringToBytes(i.toString(), true, false, []);
107
106
  pageNumber.forEach(function (entry) {
108
107
  _this._jsonData.push(entry);
109
108
  });
@@ -119,7 +118,7 @@ var _JsonDocument = /** @class */ (function (_super) {
119
118
  }
120
119
  count++;
121
120
  this._exportAnnotation(annotation, i);
122
- this._jsonData = _convertStringToBytes(this._convertToJson(this._table), this._jsonData);
121
+ this._jsonData = _stringToBytes(this._convertToJson(this._table), true, false, this._jsonData);
123
122
  this._table.clear();
124
123
  }
125
124
  }
@@ -606,16 +605,31 @@ var _JsonDocument = /** @class */ (function (_super) {
606
605
  }
607
606
  };
608
607
  _JsonDocument.prototype._writeObject = function (table, value, dictionary, key, array) {
608
+ var _this = this;
609
609
  if (value instanceof _PdfName) {
610
610
  this._writeTable('name', value.name, table, key, array);
611
611
  }
612
612
  else if (Array.isArray(value)) {
613
613
  var list = [];
614
+ if (key === 'ColorSpace') {
615
+ value.forEach(function (element) {
616
+ if (typeof element === 'string') {
617
+ _this._isColorSpace = true;
618
+ }
619
+ });
620
+ }
614
621
  this._writeArray(list, value, dictionary);
622
+ this._isColorSpace = false;
615
623
  this._writeTable('array', this._convertToJsonArray(list), table, key, array);
616
624
  }
617
625
  else if (typeof value === 'string') {
618
- this._writeTable('string', value, table, key, array);
626
+ if (this._isColorSpace) {
627
+ var bytes = _stringToBytes(value);
628
+ this._writeTable('unicodeData', _byteArrayToHexString(bytes), table, key, array);
629
+ }
630
+ else {
631
+ this._writeTable('string', value, table, key, array);
632
+ }
619
633
  }
620
634
  else if (typeof value === 'number') {
621
635
  this._writeTable(Number.isInteger(value) ? 'int' : 'fixed', value.toString(), table, key, array);
@@ -642,6 +656,13 @@ var _JsonDocument = /** @class */ (function (_super) {
642
656
  var stream = baseStream.stream;
643
657
  data = baseStream.getString(true, stream.getByteRange(stream.start, stream.end));
644
658
  }
659
+ else if (baseStream.stream && baseStream.stream.stream) {
660
+ var flateStream = baseStream.stream; // eslint-disable-line
661
+ if (flateStream.stream && flateStream.stream instanceof _PdfStream) {
662
+ var stream = flateStream.stream;
663
+ data = flateStream.getString(true, stream.getByteRange(stream.start, stream.end));
664
+ }
665
+ }
645
666
  else {
646
667
  data = value.getString(true);
647
668
  }
@@ -730,7 +751,7 @@ var _JsonDocument = /** @class */ (function (_super) {
730
751
  _JsonDocument.prototype._parseJson = function (document, data) {
731
752
  this._document = document;
732
753
  this._crossReference = document._crossReference;
733
- var stringData = _bytesToString(data);
754
+ var stringData = _bytesToString(data, true);
734
755
  if (stringData.startsWith('{') && !stringData.endsWith('}')) {
735
756
  while (stringData.length > 0 && !stringData.endsWith('}')) {
736
757
  stringData = stringData.substring(0, stringData.length - 1);
@@ -1486,6 +1507,9 @@ var _JsonDocument = /** @class */ (function (_super) {
1486
1507
  stream.dictionary.objId = value.objectNumber + ' ' + value.generationNumber;
1487
1508
  this._crossReference._cacheMap.set(value, stream);
1488
1509
  }
1510
+ else if (keys.indexOf('unicodeData') !== -1) {
1511
+ value = _bytesToString(_hexStringToByteArray(element.unicodeData, false));
1512
+ }
1489
1513
  else {
1490
1514
  value = null;
1491
1515
  }
@@ -1640,7 +1640,7 @@ var _XfdfDocument = /** @class */ (function (_super) {
1640
1640
  this._document = document;
1641
1641
  this._crossReference = document._crossReference;
1642
1642
  this._isAnnotationExport = false;
1643
- var xml = _bytesToString(data);
1643
+ var xml = _bytesToString(data, true);
1644
1644
  this._xmlDocument = (new DOMParser()).parseFromString(xml, 'text/xml');
1645
1645
  this._isAnnotationImport = true;
1646
1646
  this._readXmlData(this._xmlDocument.documentElement);
@@ -1649,7 +1649,7 @@ var _XfdfDocument = /** @class */ (function (_super) {
1649
1649
  this._document = document;
1650
1650
  this._crossReference = document._crossReference;
1651
1651
  this._isAnnotationExport = false;
1652
- this._xmlDocument = (new DOMParser()).parseFromString(_bytesToString(data), 'text/xml');
1652
+ this._xmlDocument = (new DOMParser()).parseFromString(_bytesToString(data, true), 'text/xml');
1653
1653
  this._readXmlData(this._xmlDocument.documentElement);
1654
1654
  };
1655
1655
  _XfdfDocument.prototype._readXmlData = function (root) {
@@ -52,6 +52,7 @@ export declare class _PdfCrossReference {
52
52
  _writeFontDictionary(dictionary: _PdfDictionary): void;
53
53
  _writeStream(stream: _PdfBaseStream, buffer: Array<number>, transform?: _CipherTransform, isCrossReference?: boolean): void;
54
54
  _writeValue(value: any, buffer: Array<number>, transform?: _CipherTransform, isCrossReference?: boolean): void;
55
+ _writeUnicodeString(value: string, buffer: Array<number>): void;
55
56
  _writeString(value: string, buffer: Array<number>): void;
56
57
  _writeBytes(data: number[], buffer: Array<number>): void;
57
58
  _writeLong(value: number, count: number, buffer: Array<number>): void;
@@ -1,6 +1,6 @@
1
1
  import { _PdfStream } from './base-stream';
2
2
  import { _PdfDictionary, _PdfReferenceSet, _isCommand, _PdfReference, _PdfName } from './pdf-primitives';
3
- import { BaseException, FormatError, _escapePdfName, _bytesToString, ParserEndOfFileException, _numberToString, _stringToPdfString, _getSize } from './utils';
3
+ import { BaseException, FormatError, _escapePdfName, _bytesToString, ParserEndOfFileException, _numberToString, _stringToPdfString, _getSize, _stringToBigEndianBytes } from './utils';
4
4
  import { _PdfParser, _PdfLexicalOperator } from './pdf-parser';
5
5
  import { _PdfBaseStream } from './base-stream';
6
6
  import { PdfCrossReferenceType } from './enumerator';
@@ -742,7 +742,7 @@ var _PdfCrossReference = /** @class */ (function () {
742
742
  }
743
743
  this._writeObject(archiveStream, buffer, archiveRef, cipher_2);
744
744
  }
745
- var formatValue = Math.max(_getSize(this._stream.bytes.length), _getSize(this._nextReferenceNumber));
745
+ var formatValue = Math.max(_getSize(this._stream.bytes.length + buffer.length), _getSize(this._nextReferenceNumber));
746
746
  var newRef = this._getNextReference();
747
747
  var newStartXref = currentLength + buffer.length;
748
748
  var newXref = new _PdfDictionary(this);
@@ -979,7 +979,19 @@ var _PdfCrossReference = /** @class */ (function () {
979
979
  if (!isCrossReference && transform) {
980
980
  value = transform.encryptString(value);
981
981
  }
982
- this._writeString("(" + this._escapeString(value) + ")", buffer);
982
+ var isUnicode = false;
983
+ for (var i = 0; i < value.length; i++) {
984
+ if (value.charCodeAt([i]) > 255) {
985
+ isUnicode = true;
986
+ break;
987
+ }
988
+ }
989
+ if (isUnicode) {
990
+ this._writeUnicodeString(value, buffer);
991
+ }
992
+ else {
993
+ this._writeString("(" + this._escapeString(value) + ")", buffer);
994
+ }
983
995
  }
984
996
  else if (typeof value === 'number') {
985
997
  this._writeString(_numberToString(value), buffer);
@@ -997,6 +1009,37 @@ var _PdfCrossReference = /** @class */ (function () {
997
1009
  this._writeString('null', buffer);
998
1010
  }
999
1011
  };
1012
+ _PdfCrossReference.prototype._writeUnicodeString = function (value, buffer) {
1013
+ var byteValues = _stringToBigEndianBytes(value);
1014
+ byteValues.unshift(254, 255);
1015
+ var data = [];
1016
+ for (var i = 0; i < byteValues.length; i++) {
1017
+ var byte = byteValues[Number.parseInt(i.toString(), 10)];
1018
+ switch (byte) {
1019
+ case 40:
1020
+ case 41:
1021
+ data.push(92);
1022
+ data.push(byte);
1023
+ break;
1024
+ case 13:
1025
+ data.push(92);
1026
+ data.push(114);
1027
+ break;
1028
+ case 92:
1029
+ data.push(92);
1030
+ data.push(byte);
1031
+ break;
1032
+ default:
1033
+ data.push(byte);
1034
+ break;
1035
+ }
1036
+ }
1037
+ buffer.push('('.charCodeAt(0) & 0xff);
1038
+ for (var i = 0; i < data.length; i++) {
1039
+ buffer.push(data[Number.parseInt(i.toString(), 10)] & 0xff);
1040
+ }
1041
+ buffer.push(')'.charCodeAt(0) & 0xff);
1042
+ };
1000
1043
  _PdfCrossReference.prototype._writeString = function (value, buffer) {
1001
1044
  for (var i = 0; i < value.length; i++) {
1002
1045
  buffer.push(value.charCodeAt(i) & 0xff);
@@ -55,12 +55,12 @@ var _PdfEncryptor = /** @class */ (function () {
55
55
  if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
56
56
  throw new FormatError('invalid key length');
57
57
  }
58
- var ownerPassword = _stringToBytes(dictionary.get('O')).subarray(0, 32);
59
- var userPassword = _stringToBytes(dictionary.get('U')).subarray(0, 32);
58
+ var ownerPassword = _stringToBytes(dictionary.get('O'), false, true).subarray(0, 32);
59
+ var userPassword = _stringToBytes(dictionary.get('U'), false, true).subarray(0, 32);
60
60
  var flag = dictionary.get('P');
61
61
  var revision = dictionary.get('R');
62
62
  this._encryptMetaData = (algorithm === 4 || algorithm === 5) && dictionary.get('EncryptMetadata') !== false;
63
- var fileIdBytes = _stringToBytes(id);
63
+ var fileIdBytes = _stringToBytes(id, false, true);
64
64
  var passwordBytes;
65
65
  if (password) {
66
66
  if (revision === 6) {
@@ -83,15 +83,15 @@ var _PdfEncryptor = /** @class */ (function () {
83
83
  }
84
84
  }
85
85
  else {
86
- var ownerValidationKey = _stringToBytes(dictionary.get('O'));
86
+ var ownerValidationKey = _stringToBytes(dictionary.get('O'), false, true);
87
87
  var ownerValidationSalt = ownerValidationKey.subarray(32, 40);
88
88
  var ownerKeySalt = ownerValidationKey.subarray(40, 48);
89
- var userValidationKey = _stringToBytes(dictionary.get('U'));
89
+ var userValidationKey = _stringToBytes(dictionary.get('U'), false, true);
90
90
  var uBytes = userValidationKey.subarray(0, 48);
91
91
  var userValidationSalt = userValidationKey.subarray(32, 40);
92
92
  var userKeySalt = userValidationKey.subarray(40, 48);
93
- var ownerEncryption = _stringToBytes(dictionary.get('OE'));
94
- var userEncryption = _stringToBytes(dictionary.get('UE'));
93
+ var ownerEncryption = _stringToBytes(dictionary.get('OE'), false, true);
94
+ var userEncryption = _stringToBytes(dictionary.get('UE'), false, true);
95
95
  var algorithm_1;
96
96
  if (revision === 6) {
97
97
  algorithm_1 = new _AdvancedEncryption();
@@ -1590,7 +1590,7 @@ var _CipherTransform = /** @class */ (function () {
1590
1590
  return new _PdfDecryptStream(stream, length, this._streamCipher);
1591
1591
  };
1592
1592
  _CipherTransform.prototype.decryptString = function (s) {
1593
- return _bytesToString(this._stringCipher._decryptBlock(_stringToBytes(s), true));
1593
+ return _bytesToString(this._stringCipher._decryptBlock(_stringToBytes(s, false, true), true));
1594
1594
  };
1595
1595
  _CipherTransform.prototype.encryptString = function (s) {
1596
1596
  if (this._stringCipher instanceof _AdvancedEncryptionBaseCipher) {
@@ -1606,13 +1606,13 @@ var _CipherTransform = /** @class */ (function () {
1606
1606
  iv[Number.parseInt(i.toString(), 10)] = Math.floor(256 * Math.random());
1607
1607
  }
1608
1608
  }
1609
- var data = this._stringCipher._encrypt(_stringToBytes(s), iv);
1609
+ var data = this._stringCipher._encrypt(_stringToBytes(s, false, true), iv);
1610
1610
  var buffer = new Uint8Array(16 + data.length);
1611
1611
  buffer.set(iv);
1612
1612
  buffer.set(data, 16);
1613
1613
  return _bytesToString(buffer);
1614
1614
  }
1615
- return _bytesToString(this._stringCipher._encrypt(_stringToBytes(s)));
1615
+ return _bytesToString(this._stringCipher._encrypt(_stringToBytes(s, false, true)));
1616
1616
  };
1617
1617
  return _CipherTransform;
1618
1618
  }());
@@ -104,19 +104,11 @@ export declare function _stringToPdfString(value: string): string;
104
104
  *
105
105
  * @private
106
106
  * @param {string} value string value.
107
- * @param {boolean} isDirect Whether to return object or number[]. Default is false.
108
- * @returns {Uint8Array | number[]} Byte array
109
- */
110
- export declare function _stringToBytes(value: string, isDirect?: boolean): Uint8Array | number[];
111
- /**
112
- * Convert string value to byte array
113
- *
114
- * @private
115
- * @param {string} value string value.
116
- * @param {number[]} destination byte array.
117
- * @returns {number[]} Byte array
107
+ * @param {boolean} isDirect Whether to return a number[] or Uint8Array.
108
+ * @param {boolean} isPassword Whether the string is a password.
109
+ * @returns {number[] | Uint8Array} Byte array
118
110
  */
119
- export declare function _convertStringToBytes(value: string, destination: number[]): number[];
111
+ export declare function _stringToBytes(value: string, isDirect?: boolean, isPassword?: boolean, destination?: number[]): number[] | Uint8Array;
120
112
  /**
121
113
  * Check equal or not.
122
114
  *
@@ -150,7 +142,15 @@ export declare function _areNotEqual(value: number[], current: number[]): boolea
150
142
  * @param {Uint8Array} bytes Input data.
151
143
  * @returns {string} String value processed from input bytes.
152
144
  */
153
- export declare function _bytesToString(bytes: Uint8Array): string;
145
+ export declare function _bytesToString(bytes: Uint8Array, isJson?: boolean): string;
146
+ /**
147
+ * Decode unicode string.
148
+ *
149
+ * @private
150
+ * @param {Uint8Array} bytes Input data.
151
+ * @returns {string} String value processed from input bytes.
152
+ */
153
+ export declare function _decodeUTF8(bytes: Uint8Array): string;
154
154
  /**
155
155
  * Convert string to unicode array.
156
156
  *
@@ -765,3 +765,10 @@ export declare function _decodeText(text: string, isColorSpace: boolean, isPassw
765
765
  * @returns {number} number of bytes.
766
766
  */
767
767
  export declare function _getSize(input: number): number;
768
+ /**
769
+ * Convert the string to big endian bytes.
770
+ *
771
+ * @param {string} input string.
772
+ * @returns {number[]} bytes.
773
+ */
774
+ export declare function _stringToBigEndianBytes(input: string): number[];
@@ -270,30 +270,48 @@ export function _stringToPdfString(value) {
270
270
  *
271
271
  * @private
272
272
  * @param {string} value string value.
273
- * @param {boolean} isDirect Whether to return object or number[]. Default is false.
274
- * @returns {Uint8Array | number[]} Byte array
273
+ * @param {boolean} isDirect Whether to return a number[] or Uint8Array.
274
+ * @param {boolean} isPassword Whether the string is a password.
275
+ * @returns {number[] | Uint8Array} Byte array
275
276
  */
276
- export function _stringToBytes(value, isDirect) {
277
+ export function _stringToBytes(value, isDirect, isPassword, destination) {
277
278
  if (isDirect === void 0) { isDirect = false; }
279
+ if (isPassword === void 0) { isPassword = false; }
278
280
  var bytes = [];
279
- for (var i = 0; i < value.length; ++i) {
280
- bytes.push(value.charCodeAt(i) & 0xff);
281
+ if (destination) {
282
+ bytes = destination;
281
283
  }
282
- return isDirect ? bytes : new Uint8Array(bytes);
283
- }
284
- /**
285
- * Convert string value to byte array
286
- *
287
- * @private
288
- * @param {string} value string value.
289
- * @param {number[]} destination byte array.
290
- * @returns {number[]} Byte array
291
- */
292
- export function _convertStringToBytes(value, destination) {
293
- for (var i = 0; i < value.length; ++i) {
294
- destination.push(value.charCodeAt(i) & 0xff);
284
+ if (isPassword) {
285
+ for (var i = 0; i < value.length; i++) {
286
+ bytes.push(value.charCodeAt(i));
287
+ }
295
288
  }
296
- return destination;
289
+ else {
290
+ for (var i = 0; i < value.length; i++) {
291
+ var charCode = value.charCodeAt(i);
292
+ if (charCode < 0x80) {
293
+ bytes.push(charCode);
294
+ }
295
+ else if (charCode < 0x800) {
296
+ bytes.push((charCode >> 6) | 0xC0);
297
+ bytes.push((charCode & 0x3F) | 0x80);
298
+ }
299
+ else if (charCode < 0xD800 || charCode >= 0xE000) {
300
+ bytes.push((charCode >> 12) | 0xE0);
301
+ bytes.push(((charCode >> 6) & 0x3F) | 0x80);
302
+ bytes.push((charCode & 0x3F) | 0x80);
303
+ }
304
+ else {
305
+ i++;
306
+ charCode = 0x10000 + (((charCode & 0x3FF) << 10) | (value.charCodeAt(i) & 0x3FF));
307
+ bytes.push((charCode >> 18) | 0xF0);
308
+ bytes.push(((charCode >> 12) & 0x3F) | 0x80);
309
+ bytes.push(((charCode >> 6) & 0x3F) | 0x80);
310
+ bytes.push((charCode & 0x3F) | 0x80);
311
+ }
312
+ }
313
+ }
314
+ return isDirect ? bytes : new Uint8Array(bytes);
297
315
  }
298
316
  /**
299
317
  * Check equal or not.
@@ -355,20 +373,49 @@ export function _areNotEqual(value, current) {
355
373
  * @param {Uint8Array} bytes Input data.
356
374
  * @returns {string} String value processed from input bytes.
357
375
  */
358
- export function _bytesToString(bytes) {
376
+ export function _bytesToString(bytes, isJson) {
377
+ if (isJson === void 0) { isJson = false; }
359
378
  var length = bytes.length;
360
379
  var max = 8192;
380
+ var stringBuffer = [];
361
381
  if (length < max) {
362
- return String.fromCharCode.apply(null, bytes);
382
+ return (isJson ? _decodeUTF8(bytes) : String.fromCharCode.apply(null, bytes));
363
383
  }
364
- var stringBuffer = [];
365
384
  for (var i = 0; i < length; i += max) {
366
385
  var chunkEnd = Math.min(i + max, length);
367
386
  var chunk = bytes.subarray(i, chunkEnd);
368
- stringBuffer.push(String.fromCharCode.apply(null, chunk));
387
+ stringBuffer.push(isJson ? _decodeUTF8(chunk) : String.fromCharCode.apply(null, chunk));
369
388
  }
370
389
  return stringBuffer.join('');
371
390
  }
391
+ /**
392
+ * Decode unicode string.
393
+ *
394
+ * @private
395
+ * @param {Uint8Array} bytes Input data.
396
+ * @returns {string} String value processed from input bytes.
397
+ */
398
+ export function _decodeUTF8(bytes) {
399
+ var result = '';
400
+ var i = 0;
401
+ while (i < bytes.length) {
402
+ var byte = bytes[i++];
403
+ if (byte < 0x80) {
404
+ result += String.fromCharCode(byte);
405
+ }
406
+ else if (byte < 0xE0) {
407
+ result += String.fromCharCode(((byte & 0x1F) << 6) | (bytes[i++] & 0x3F));
408
+ }
409
+ else if (byte < 0xF0) {
410
+ result += String.fromCharCode(((byte & 0x0F) << 12) | ((bytes[i++] & 0x3F) << 6) | (bytes[i++] & 0x3F));
411
+ }
412
+ else {
413
+ var codePoint = ((byte & 0x07) << 18) | ((bytes[i++] & 0x3F) << 12) | ((bytes[i++] & 0x3F) << 6) | (bytes[i++] & 0x3F) - 0x10000;
414
+ result += String.fromCharCode((codePoint >> 10) + 0xD800, (codePoint & 0x03FF) + 0xDC00);
415
+ }
416
+ }
417
+ return result;
418
+ }
372
419
  /**
373
420
  * Convert string to unicode array.
374
421
  *
@@ -3991,3 +4038,20 @@ export function _getSize(input) {
3991
4038
  }
3992
4039
  return size;
3993
4040
  }
4041
+ /**
4042
+ * Convert the string to big endian bytes.
4043
+ *
4044
+ * @param {string} input string.
4045
+ * @returns {number[]} bytes.
4046
+ */
4047
+ export function _stringToBigEndianBytes(input) {
4048
+ var bytes = [];
4049
+ for (var i = 0; i < input.length; i++) {
4050
+ var charCode = input.charCodeAt(Number.parseInt(i.toString(), 10));
4051
+ if (charCode <= 0xFFFF) {
4052
+ bytes.push((charCode >> 8) & 0xFF);
4053
+ bytes.push(charCode & 0xFF);
4054
+ }
4055
+ }
4056
+ return bytes;
4057
+ }