Skip to content

Commit 8f14340

Browse files
committed
Style improvements
1 parent f662731 commit 8f14340

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

src/lib/libfetchfs.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ addToLibrary({
88
$FETCHFS__deps: ['$stringToUTF8OnStack', 'wasmfs_create_fetch_backend'],
99
$FETCHFS: {
1010
createBackend(opts) {
11-
opts.base_url ??= "";
1211
return withStackSave(() => {
13-
return _wasmfs_create_fetch_backend(stringToUTF8OnStack(opts.base_url), opts.chunkSize | 0);
12+
return _wasmfs_create_fetch_backend(stringToUTF8OnStack(opts.base_url ?? ""), opts.chunkSize | 0);
1413
});
1514
},
1615
},

src/lib/libwasmfs_fetch.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ addToLibrary({
3737
}
3838
var chunkSize = __wasmfs_fetch_get_chunk_size(file);
3939
offset ??= 0;
40-
len = len || chunkSize;
40+
len ??= chunkSize;
4141
var firstChunk = (offset / chunkSize) | 0;
4242
var lastChunk = ((offset+len) / chunkSize) | 0;
4343
if (!(file in wasmFS$JSMemoryRanges)) {
@@ -46,7 +46,11 @@ addToLibrary({
4646
fileInfo.headers.has("Content-Length") &&
4747
fileInfo.headers.get("Accept-Ranges") == "bytes" &&
4848
(parseInt(fileInfo.headers.get("Content-Length")) > chunkSize*2)) {
49-
wasmFS$JSMemoryRanges[file] = {size:parseInt(fileInfo.headers.get("Content-Length")), chunks:[], chunkSize:chunkSize};
49+
wasmFS$JSMemoryRanges[file] = {
50+
size:parseInt(fileInfo.headers.get("Content-Length")),
51+
chunks:[],
52+
chunkSize:chunkSize
53+
};
5054
} else {
5155
// may as well/forced to download the whole file
5256
var wholeFileReq = await fetch(url);
@@ -55,7 +59,11 @@ addToLibrary({
5559
}
5660
var wholeFileData = new Uint8Array(await wholeFileReq.arrayBuffer());
5761
var text = new TextDecoder().decode(wholeFileData);
58-
wasmFS$JSMemoryRanges[file] = {size:wholeFileData.byteLength, chunks:[wholeFileData], chunkSize:wholeFileData.byteLength};
62+
wasmFS$JSMemoryRanges[file] = {
63+
size:wholeFileData.byteLength,
64+
chunks:[wholeFileData],
65+
chunkSize:wholeFileData.byteLength
66+
};
5967
return Promise.resolve();
6068
}
6169
}

system/include/emscripten/wasmfs.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ backend_t wasmfs_create_memory_backend(void);
5959
// and ending with whatever the file's path is relative to where the
6060
// fetchfs directory is mounted.
6161
//
62+
// Individual range requests will be no bigger than chunk_size, and will
63+
// be aligned to boundaries of chunk_size. Files smaller than chunk_size
64+
// will be downloaded all at once.
65+
//
66+
// If chunk_size is 0, a reasonable default value will be used.
6267
//
6368
// Note: this cannot be called on the browser main thread because it might
6469
// deadlock while waiting for its dedicated worker thread to be spawned.
@@ -71,7 +76,7 @@ backend_t wasmfs_create_memory_backend(void);
7176
// thread.
7277
//
7378
backend_t wasmfs_create_fetch_backend(const char* base_url __attribute__((nonnull)),
74-
uint32_t chunkSize);
79+
uint32_t chunk_size);
7580

7681
backend_t wasmfs_create_node_backend(const char* root __attribute__((nonnull)));
7782

system/lib/wasmfs/backends/fetch_backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ std::shared_ptr<Directory> FetchBackend::createDirectory(mode_t mode) {
9494
}
9595

9696
const std::string FetchBackend::getFileURL(const std::string& filePath) {
97-
if(filePath == "") {
97+
if (filePath == "") {
9898
return baseUrl;
9999
}
100100
return baseUrl + "/" + filePath;

test/wasmfs/wasmfs_fetch.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void check_file(int fd, const char* content) {
4343
void test_url_relative() {
4444
printf("Running %s...\n", __FUNCTION__);
4545

46-
backend_t backend2 = wasmfs_create_fetch_backend("test.txt",0);
46+
backend_t backend2 = wasmfs_create_fetch_backend("test.txt", 0);
4747
int fd = wasmfs_create_file("/file_rel", 0777, backend2);
4848
check_file(fd, "fetch 2");
4949
assert(close(fd) == 0);
@@ -57,7 +57,7 @@ void test_url_absolute() {
5757
char url[200];
5858
snprintf(url, sizeof(url), "%s%s", url_orig, file_name);
5959

60-
backend_t backend = wasmfs_create_fetch_backend(url,0);
60+
backend_t backend = wasmfs_create_fetch_backend(url, 0);
6161
int fd = wasmfs_create_file(file_name, 0777, backend);
6262
check_file(fd, "fetch 2");
6363
assert(close(fd) == 0);
@@ -70,7 +70,7 @@ void test_directory_abs() {
7070
char url[200];
7171
snprintf(url, sizeof(url), "%s%s", url_orig, dir_path);
7272

73-
backend_t backend = wasmfs_create_fetch_backend(url,0);
73+
backend_t backend = wasmfs_create_fetch_backend(url, 0);
7474
int res = wasmfs_create_directory(dir_path, 0777, backend);
7575
if (errno)
7676
perror("wasmfs_create_directory");
@@ -101,7 +101,7 @@ void test_directory_abs() {
101101

102102
void test_default() {
103103
printf("Running %s...\n", __FUNCTION__);
104-
backend_t backend = wasmfs_create_fetch_backend("data.dat",0);
104+
backend_t backend = wasmfs_create_fetch_backend("data.dat", 0);
105105

106106
// Create a file in that backend.
107107
int fd = wasmfs_create_file("/testfile", 0777, backend);
@@ -137,7 +137,7 @@ void test_small_reads() {
137137
char expected[] = "hello";
138138
size_t size = 5;
139139

140-
backend_t backend = wasmfs_create_fetch_backend("small.dat",0);
140+
backend_t backend = wasmfs_create_fetch_backend("small.dat", 0);
141141
int fd = wasmfs_create_file("/testfile3", 0777, backend);
142142
char buf[size + 1];
143143
for (size_t i = 0; i < size; i++) {

0 commit comments

Comments
 (0)