Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
9c2c48bd
Commit
9c2c48bd
authored
5 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
use TextDecoder when available
parent
df6d49b2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mol-io/common/utf8.ts
+12
-2
12 additions, 2 deletions
src/mol-io/common/utf8.ts
with
12 additions
and
2 deletions
src/mol-io/common/utf8.ts
+
12
−
2
View file @
9c2c48bd
/**
* 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
++
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment