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
445977d9
Commit
445977d9
authored
2 years ago
by
dsehnal
Browse files
Options
Downloads
Patches
Plain Diff
Fix data-source node workaround
parent
a748b158
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
-7
10 additions, 7 deletions
src/mol-util/data-source.ts
with
10 additions
and
7 deletions
src/mol-util/data-source.ts
+
10
−
7
View file @
445977d9
...
@@ -11,16 +11,10 @@
...
@@ -11,16 +11,10 @@
import
{
utf8Read
}
from
'
../mol-io/common/utf8
'
;
import
{
utf8Read
}
from
'
../mol-io/common/utf8
'
;
import
{
RuntimeContext
,
Task
}
from
'
../mol-task
'
;
import
{
RuntimeContext
,
Task
}
from
'
../mol-task
'
;
import
{
Asset
,
AssetManager
}
from
'
./assets
'
;
import
{
Asset
,
AssetManager
}
from
'
./assets
'
;
import
{
LazyImports
}
from
'
./lazy-imports
'
;
import
{
File_
as
File
,
RUNNING_IN_NODEJS
,
XMLHttpRequest_
as
XMLHttpRequest
}
from
'
./nodejs-shims
'
;
import
{
File_
as
File
,
RUNNING_IN_NODEJS
,
XMLHttpRequest_
as
XMLHttpRequest
}
from
'
./nodejs-shims
'
;
import
{
ungzip
,
unzip
}
from
'
./zip/zip
'
;
import
{
ungzip
,
unzip
}
from
'
./zip/zip
'
;
const
lazyImports
=
LazyImports
.
create
(
'
fs
'
)
as
{
'
fs
'
:
typeof
import
(
'
fs
'
),
};
export
enum
DataCompressionMethod
{
export
enum
DataCompressionMethod
{
None
,
None
,
Gzip
,
Gzip
,
...
@@ -306,12 +300,21 @@ function ajaxGetInternal<T extends DataType>(title: string | undefined, url: str
...
@@ -306,12 +300,21 @@ function ajaxGetInternal<T extends DataType>(title: string | undefined, url: str
});
});
}
}
// NOTE: lazy imports cannot be used here because WebPack complains since this
// is part of the "browser" build.
let
_fs
:
(
typeof
import
(
'
fs
'
))
|
undefined
=
undefined
;
function
getFS
()
{
if
(
_fs
)
return
_fs
!
;
_fs
=
require
(
'
fs
'
);
return
_fs
!
;
}
/** Alternative implementation of ajaxGetInternal (because xhr2 does not support file:// protocol) */
/** Alternative implementation of ajaxGetInternal (because xhr2 does not support file:// protocol) */
function
ajaxGetInternal_file_NodeJS
<
T
extends
DataType
>
(
title
:
string
|
undefined
,
url
:
string
,
type
:
T
,
body
?:
string
,
headers
?:
[
string
,
string
][]):
Task
<
DataResponse
<
T
>>
{
function
ajaxGetInternal_file_NodeJS
<
T
extends
DataType
>
(
title
:
string
|
undefined
,
url
:
string
,
type
:
T
,
body
?:
string
,
headers
?:
[
string
,
string
][]):
Task
<
DataResponse
<
T
>>
{
if
(
!
RUNNING_IN_NODEJS
)
throw
new
Error
(
'
This function should only be used when running in Node.js
'
);
if
(
!
RUNNING_IN_NODEJS
)
throw
new
Error
(
'
This function should only be used when running in Node.js
'
);
if
(
!
url
.
startsWith
(
'
file://
'
))
throw
new
Error
(
'
This function is only for URLs with protocol file://
'
);
if
(
!
url
.
startsWith
(
'
file://
'
))
throw
new
Error
(
'
This function is only for URLs with protocol file://
'
);
const
filename
=
url
.
substring
(
'
file://
'
.
length
);
const
filename
=
url
.
substring
(
'
file://
'
.
length
);
const
data
=
lazyImports
.
fs
.
readFileSync
(
filename
);
const
data
=
getFS
()
.
readFileSync
(
filename
);
const
file
=
new
File
([
data
],
'
raw-data
'
);
const
file
=
new
File
([
data
],
'
raw-data
'
);
return
readFromFile
(
file
,
type
);
return
readFromFile
(
file
,
type
);
}
}
...
...
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