Skip to content

Commit f85b395

Browse files
committed
feat: improve register
1 parent 40552e0 commit f85b395

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlite-vfs-http"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
authors = ["DarkSky <darksky2048@gmail.com>"]
66
license = "AGPL-3.0-only"

src/lib.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,38 @@ use vfs::HttpVfs;
1212

1313
pub use vfs::HTTP_VFS;
1414

15-
pub fn register_http_vfs() {
16-
const ONCE: Once = Once::new();
15+
pub struct HttpVfsRegister {
16+
block_size: usize,
17+
download_threshold: usize,
18+
}
19+
20+
impl HttpVfsRegister {
21+
pub fn new() -> Self {
22+
Self {
23+
block_size: 1024 * 1024 * 4,
24+
download_threshold: 1024,
25+
}
26+
}
27+
28+
pub fn with_block_size(self, block_size: usize) -> Self {
29+
Self { block_size, ..self }
30+
}
31+
32+
pub fn register(self) {
33+
const ONCE: Once = Once::new();
1734

18-
ONCE.call_once(|| {
19-
let _ = register(HTTP_VFS, HttpVfs::default(), true);
20-
})
35+
let vfs_instance = HttpVfs {
36+
block_size: self.block_size,
37+
download_threshold: self.download_threshold,
38+
};
39+
40+
ONCE.call_once(|| {
41+
let _ = register(HTTP_VFS, vfs_instance, true);
42+
})
43+
}
44+
}
45+
46+
#[inline(always)]
47+
pub fn register_http_vfs() {
48+
HttpVfsRegister::new().register();
2149
}

0 commit comments

Comments
 (0)