|
@@ -1,5 +1,5 @@
|
|
|
/**
|
|
|
- * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
+ * Copyright (c) 2017-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
*
|
|
|
* Adapted from https://github.com/rcsb/mmtf-javascript
|
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
@@ -53,7 +53,7 @@ function throwError(err: string) {
|
|
|
throw new Error(err);
|
|
|
}
|
|
|
|
|
|
-export function utf8Read(data: Uint8Array, offset: number, length: number) {
|
|
|
+function _utf8Read(data: Uint8Array, offset: number, length: number) {
|
|
|
let chars = __chars;
|
|
|
let str: string[] | undefined = void 0, chunk: string[] = [], chunkSize = 512, chunkOffset = 0;
|
|
|
|
|
@@ -98,6 +98,16 @@ export function utf8Read(data: Uint8Array, offset: number, length: number) {
|
|
|
return str.join('');
|
|
|
}
|
|
|
|
|
|
+const utf8Decoder = (typeof TextDecoder !== 'undefined') ? new TextDecoder() : undefined
|
|
|
+export function utf8Read(data: Uint8Array, offset: number, length: number) {
|
|
|
+ if (utf8Decoder) {
|
|
|
+ const input = (offset || length !== data.length) ? data.subarray(offset, offset + length) : data
|
|
|
+ return utf8Decoder.decode(input)
|
|
|
+ } else {
|
|
|
+ return _utf8Read(data, offset, length)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export function utf8ByteCount(str: string) {
|
|
|
let count = 0;
|
|
|
for (let i = 0, l = str.length; i < l; i++) {
|