Skip to content

Commit 5eeb8d5

Browse files
just use tower compression
1 parent 8b6ae8f commit 5eeb8d5

File tree

3 files changed

+5
-25
lines changed

3 files changed

+5
-25
lines changed

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() -> Result<(), anyhow::Error> {
3838

3939
let output = wasm_bindgen::generate(&options, &wasm_file)?;
4040

41-
info!("compressed wasm output is {} large", pretty_size(output.compressed_wasm.len()));
41+
info!("uncompressed wasm output is {} large", pretty_size(output.wasm.len()));
4242

4343
let rt = tokio::runtime::Runtime::new()?;
4444
rt.block_on(server::run_server(options, output))?;

src/server.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct Options {
2929
}
3030

3131
pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<()> {
32-
let WasmBindgenOutput { js, compressed_wasm, snippets, local_modules } = output;
32+
let WasmBindgenOutput { js, wasm, snippets, local_modules } = output;
3333

3434
let middleware_stack = ServiceBuilder::new()
3535
.layer(CompressionLayer::new())
@@ -58,9 +58,7 @@ pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<(
5858
let serve_dir =
5959
get_service(ServeDir::new(options.directory)).handle_error(internal_server_error);
6060

61-
let serve_wasm = || async move {
62-
([("content-encoding", "br")], WithContentType("application/wasm", compressed_wasm))
63-
};
61+
let serve_wasm = || async move { WithContentType("application/wasm", wasm) };
6462

6563
let app = Router::new()
6664
.route("/", get(move || async { Html(html) }))

src/wasm_bindgen.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::server::Options;
22
use crate::Result;
3-
use anyhow::Context;
43
use std::collections::HashMap;
54
use std::path::Path;
65
use tracing::debug;
76

87
pub struct WasmBindgenOutput {
98
pub js: String,
10-
pub compressed_wasm: Vec<u8>,
9+
pub wasm: Vec<u8>,
1110
pub snippets: HashMap<String, Vec<String>>,
1211
pub local_modules: HashMap<String, String>,
1312
}
@@ -35,22 +34,5 @@ pub fn generate(options: &Options, wasm_file: &Path) -> Result<WasmBindgenOutput
3534
let wasm = output.wasm_mut().emit_wasm();
3635
debug!("emitting wasm took {:?}", start.elapsed());
3736

38-
debug!("compressing wasm...");
39-
let start = std::time::Instant::now();
40-
let compressed_wasm = compress(&wasm).context("failed to compress wasm file")?;
41-
debug!("compressing took {:?}", start.elapsed());
42-
43-
Ok(WasmBindgenOutput { js, compressed_wasm, snippets, local_modules })
44-
}
45-
46-
fn compress(mut bytes: &[u8]) -> Result<Vec<u8>, std::io::Error> {
47-
use brotli::enc::{self, BrotliEncoderParams};
48-
49-
let mut output = Vec::new();
50-
enc::BrotliCompress(&mut bytes, &mut output, &BrotliEncoderParams {
51-
quality: 5, // https://github.com/jakobhellermann/wasm-server-runner/pull/22#issuecomment-1235804905
52-
..Default::default()
53-
})?;
54-
55-
Ok(output)
37+
Ok(WasmBindgenOutput { js, wasm, snippets, local_modules })
5638
}

0 commit comments

Comments
 (0)