FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
emscripten/tests/fs/test_workerfs_package.cpp at incoming · JavaScriptIOT/emscripten · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
JavaScriptIOT
/
emscripten
Public
forked from
emscripten-core/emscripten
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
emscripten
/
tests
/
fs
/
test_workerfs_package.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
87 lines (71 loc) · 2.09 KB
Breadcrumbs
emscripten
/
tests
/
fs
/
test_workerfs_package.cpp
Copy path
File metadata and controls
87 lines (71 loc) · 2.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#
include
<
stdio.h
>
#
include
<
string.h
>
#
include
<
assert.h
>
#
include
<
emscripten.h
>
extern
"
C
"
{
void
EMSCRIPTEN_KEEPALIVE
finish
() {
//
load some file data, SYNCHRONOUSLY :)
char
buffer[
100
];
int
num;
printf
(
"
load first file
\n
"
);
FILE
*f1 =
fopen
(
"
files/file1.txt
"
,
"
r
"
);
assert
(f1);
num =
fread
(buffer,
1
,
5
, f1);
assert
(num ==
5
);
fclose
(f1);
buffer[
5
] =
0
;
assert
(
strcmp
(buffer,
"
first
"
) ==
0
);
printf
(
"
load second file
\n
"
);
FILE
*f2 =
fopen
(
"
files/sub/file2.txt
"
,
"
r
"
);
assert
(f2);
num =
fread
(buffer,
1
,
6
, f2);
assert
(num ==
6
);
fclose
(f2);
buffer[
6
] =
0
;
assert
(
strcmp
(buffer,
"
second
"
) ==
0
);
//
all done
printf
(
"
success
\n
"
);
REPORT_RESULT
(
1
);
}
}
int
main
() {
//
Load the metadata and data of our file package. When they arrive, load the contents of the package into our filesystem.
//
The data arrives as a Blob, which could in other cases arrive from any other way a Blob can arrive:
//
* Local file the user selected
//
* Data loaded from IndexedDB
//
In all cases, including the one here of a network request, Blobs allow the browser to optimize them so that
//
a large file is not necessarily all in memory at once.
EM_ASM
((
var meta, blob;
function
maybeReady
() {
if
(!(meta && blob))
return
;
meta =
JSON
.
parse
(meta);
Module.
print
(
'
loading into filesystem
'
);
FS
.
mkdir
(
'
/files
'
);
FS
.
mount
(
WORKERFS
, {
packages: [{ metadata: meta, blob: blob }]
},
'
/files
'
);
ccall
(
'
finish
'
);
}
var meta_xhr =
new
XMLHttpRequest
();
meta_xhr.
open
(
"
GET
"
,
"
files.js.metadata
"
,
true
);
meta_xhr.
responseType
=
"
text
"
;
meta_xhr.
onload
=
function
() {
Module.
print
(
'
got metadata
'
);
meta = meta_xhr.
response
;
maybeReady
();
};
meta_xhr.
send
();
var data_xhr =
new
XMLHttpRequest
();
data_xhr.
open
(
"
GET
"
,
"
files.data
"
,
true
);
data_xhr.
responseType
=
"
blob
"
;
data_xhr.
onload
=
function
() {
Module.
print
(
'
got data
'
);
blob = data_xhr.
response
;
maybeReady
();
};
data_xhr.
send
();
));
emscripten_exit_with_live_runtime
();
return
1
;
}
Back
|
FazBrowse Home
|
New Git URL