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
c176313f
Commit
c176313f
authored
5 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
added zip data type that returns object of Uint8Arrays
parent
77461d5a
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-util/data-source.ts
+10
-5
10 additions, 5 deletions
src/mol-util/data-source.ts
with
10 additions
and
5 deletions
src/mol-util/data-source.ts
+
10
−
5
View file @
c176313f
...
@@ -28,13 +28,14 @@ export enum DataCompressionMethod {
...
@@ -28,13 +28,14 @@ export enum DataCompressionMethod {
Zip
,
Zip
,
}
}
type
DataType
=
'
json
'
|
'
xml
'
|
'
string
'
|
'
binary
'
type
DataType
=
'
json
'
|
'
xml
'
|
'
string
'
|
'
binary
'
|
'
zip
'
type
DataValue
=
'
string
'
|
any
|
XMLDocument
|
Uint8Array
type
DataValue
=
'
string
'
|
any
|
XMLDocument
|
Uint8Array
type
DataResponse
<
T
extends
DataType
>
=
type
DataResponse
<
T
extends
DataType
>
=
T
extends
'
json
'
?
any
:
T
extends
'
json
'
?
any
:
T
extends
'
xml
'
?
XMLDocument
:
T
extends
'
xml
'
?
XMLDocument
:
T
extends
'
string
'
?
string
:
T
extends
'
string
'
?
string
:
T
extends
'
binary
'
?
Uint8Array
:
never
T
extends
'
binary
'
?
Uint8Array
:
T
extends
'
zip
'
?
{
[
k
:
string
]:
Uint8Array
}
:
never
export
interface
AjaxGetParams
<
T
extends
DataType
=
'
string
'
>
{
export
interface
AjaxGetParams
<
T
extends
DataType
=
'
string
'
>
{
url
:
string
,
url
:
string
,
...
@@ -158,6 +159,8 @@ async function processFile<T extends DataType>(ctx: RuntimeContext, reader: File
...
@@ -158,6 +159,8 @@ async function processFile<T extends DataType>(ctx: RuntimeContext, reader: File
if
(
type
===
'
binary
'
&&
data
instanceof
Uint8Array
)
{
if
(
type
===
'
binary
'
&&
data
instanceof
Uint8Array
)
{
return
data
as
DataResponse
<
T
>
;
return
data
as
DataResponse
<
T
>
;
}
else
if
(
type
===
'
zip
'
&&
data
instanceof
Uint8Array
)
{
return
await
unzip
(
ctx
,
data
.
buffer
)
as
DataResponse
<
T
>
;
}
else
if
(
type
===
'
string
'
&&
typeof
data
===
'
string
'
)
{
}
else
if
(
type
===
'
string
'
&&
typeof
data
===
'
string
'
)
{
return
data
as
DataResponse
<
T
>
;
return
data
as
DataResponse
<
T
>
;
}
else
if
(
type
===
'
xml
'
&&
typeof
data
===
'
string
'
)
{
}
else
if
(
type
===
'
xml
'
&&
typeof
data
===
'
string
'
)
{
...
@@ -174,9 +177,10 @@ function readFromFileInternal<T extends DataType>(file: File, type: T): Task<Dat
...
@@ -174,9 +177,10 @@ function readFromFileInternal<T extends DataType>(file: File, type: T): Task<Dat
return
Task
.
create
(
'
Read File
'
,
async
ctx
=>
{
return
Task
.
create
(
'
Read File
'
,
async
ctx
=>
{
try
{
try
{
reader
=
new
FileReader
();
reader
=
new
FileReader
();
const
compression
=
getCompression
(
file
.
name
);
// unzipping for type 'zip' handled explicitly in `processFile`
const
compression
=
type
===
'
zip
'
?
DataCompressionMethod
.
None
:
getCompression
(
file
.
name
);
if
(
type
===
'
binary
'
||
compression
!==
DataCompressionMethod
.
None
)
{
if
(
type
===
'
binary
'
||
type
===
'
zip
'
||
compression
!==
DataCompressionMethod
.
None
)
{
reader
.
readAsArrayBuffer
(
file
);
reader
.
readAsArrayBuffer
(
file
);
}
else
{
}
else
{
reader
.
readAsText
(
file
);
reader
.
readAsText
(
file
);
...
@@ -224,7 +228,7 @@ function processAjax<T extends DataType>(req: XMLHttpRequest, type: T): DataResp
...
@@ -224,7 +228,7 @@ function processAjax<T extends DataType>(req: XMLHttpRequest, type: T): DataResp
const
{
response
}
=
req
;
const
{
response
}
=
req
;
RequestPool
.
deposit
(
req
);
RequestPool
.
deposit
(
req
);
if
(
type
===
'
binary
'
&&
response
instanceof
ArrayBuffer
)
{
if
(
(
type
===
'
binary
'
||
type
===
'
zip
'
)
&&
response
instanceof
ArrayBuffer
)
{
return
new
Uint8Array
(
response
)
as
DataResponse
<
T
>
;
return
new
Uint8Array
(
response
)
as
DataResponse
<
T
>
;
}
else
if
(
type
===
'
string
'
&&
typeof
response
===
'
string
'
)
{
}
else
if
(
type
===
'
string
'
&&
typeof
response
===
'
string
'
)
{
return
response
as
DataResponse
<
T
>
;
return
response
as
DataResponse
<
T
>
;
...
@@ -247,6 +251,7 @@ function getRequestResponseType(type: DataType): XMLHttpRequestResponseType {
...
@@ -247,6 +251,7 @@ function getRequestResponseType(type: DataType): XMLHttpRequestResponseType {
case
'
xml
'
:
return
'
document
'
;
case
'
xml
'
:
return
'
document
'
;
case
'
string
'
:
return
'
text
'
;
case
'
string
'
:
return
'
text
'
;
case
'
binary
'
:
return
'
arraybuffer
'
;
case
'
binary
'
:
return
'
arraybuffer
'
;
case
'
zip
'
:
return
'
arraybuffer
'
;
}
}
}
}
...
...
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