Skip to content

Commit 22051d1

Browse files
committed
Add wasm support
1 parent 66901c9 commit 22051d1

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

Cargo.lock

Lines changed: 130 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@ description = "Library for compressing and decompressing DNA sequences"
77
license = "MIT"
88
repository = "https://github.com/marshallku/base-sequence-compression"
99

10+
[lib]
11+
crate-type = ["cdylib", "rlib"]
12+
1013
[dependencies]
1114
flate2 = "1.0.35"
15+
wasm-bindgen = "0.2.99"
16+
17+
[target.'cfg(target_arch = "wasm32")'.dependencies]
18+
web-sys = { version = "0.3", features = ["File", "Blob"] }
19+
js-sys = "0.3"

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,19 @@ pub fn decompress_sequence(compressed: &[u8], sequence_length: usize) -> io::Res
107107
}
108108

109109
/// A struct that represents a FASTA file compressor.
110+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
110111
pub struct FASTACompressor;
111112

112113
/// Compressor methods for the FASTA file format.
114+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
113115
impl FASTACompressor {
116+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(constructor))]
114117
pub fn new() -> Self {
115118
FASTACompressor
116119
}
117120

118121
/// Compresses a FASTA file content into a vector of bytes.
122+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
119123
pub fn compress(&self, content: &str) -> Vec<u8> {
120124
let mut lines = content.lines();
121125
let header = lines.next().unwrap_or("").to_string();

0 commit comments

Comments
 (0)