feat: Expose the sled compression setting

This commit is contained in:
Clément Renault 2019-05-20 14:41:15 +02:00
parent 349f0f7068
commit 2e79b2a871
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE
2 changed files with 16 additions and 0 deletions

View File

@ -28,5 +28,9 @@ rev = "40b3d48"
git = "https://github.com/Kerollmops/fst.git" git = "https://github.com/Kerollmops/fst.git"
branch = "arc-byte-slice" branch = "arc-byte-slice"
[features]
default = []
compression = ["sled/compression"]
[dev-dependencies] [dev-dependencies]
tempfile = "3.0.7" tempfile = "3.0.7"

View File

@ -41,6 +41,18 @@ impl Database {
Ok(Database { cache, inner }) Ok(Database { cache, inner })
} }
pub fn start_with_compression<P: AsRef<Path>>(path: P, factor: i32) -> Result<Database, Error> {
let config = sled::ConfigBuilder::default()
.use_compression(true)
.compression_factor(factor)
.path(path)
.build();
let cache = RwLock::new(HashMap::new());
let inner = sled::Db::start(config)?;
Ok(Database { cache, inner })
}
pub fn indexes(&self) -> Result<Option<HashSet<String>>, Error> { pub fn indexes(&self) -> Result<Option<HashSet<String>>, Error> {
let bytes = match self.inner.get("indexes")? { let bytes = match self.inner.get("indexes")? {
Some(bytes) => bytes, Some(bytes) => bytes,