Skip to content

Commit a42dc04

Browse files
fix: pipelines: add missing compression support for custom initializer
Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
1 parent d59f065 commit a42dc04

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/pipelines/rust/initializer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
async function __trunkInitializer(init, source, sourceSize, initializer, initWithObject) {
1+
async function __trunkInitializer(init, source, sourceSize, initializer, initWithObject, compressAlgorithm) {
22
if (initializer === undefined) {
33
return await init(initWithObject ? { module_or_path: source } : source);
44
}
@@ -11,14 +11,20 @@ async function __trunkInitializer(init, source, sourceSize, initializer, initWit
1111

1212
const response = fetch(source)
1313
.then((response) => {
14-
const reader = response.body.getReader();
1514
const headers = response.headers;
1615
const status = response.status;
1716
const statusText = response.statusText;
1817

1918
const total = sourceSize;
2019
let current = 0;
2120

21+
let reader = undefined;
22+
if (compressAlgorithm) {
23+
reader = response.body.pipeThrough(new DecompressionStream(compressAlgorithm)).getReader();
24+
} else {
25+
reader = response.body.getReader();
26+
}
27+
2228
const stream = new ReadableStream({
2329
start(controller) {
2430
function push() {

src/pipelines/rust/output.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,18 @@ const wasm = await init({init_arg});
187187
import init{import} from '{base}{js}';
188188
import initializer from '{base}{initializer}';
189189
190-
const wasm = await __trunkInitializer(init, '{base}{wasm}', {size}, initializer(), {init_with_object});
190+
const wasm = await __trunkInitializer(init, '{base}{wasm}', {size}, initializer(), {init_with_object}{algorithm});
191191
192192
{bind}
193193
{fire}
194194
</script>"#,
195195
init = include_str!("initializer.js"),
196196
size = self.wasm_size,
197+
algorithm = if let Some(algorithm) = &self.compression_algorithm {
198+
format!(", '{algorithm}'")
199+
} else {
200+
String::new()
201+
},
197202
),
198203
}
199204
}

0 commit comments

Comments
 (0)