use std::path::Path;
use infrastore_core::{Compression, Store, create_store, open_store};
pub fn open_readonly(path: &Path) -> Result<Store, String> {
if !path.exists() {
return Err(format!("store not found: {}", path.display()));
}
open_store(path, true).map_err(|e| e.to_string())
}
pub fn open_writable(path: &Path) -> Result<Store, String> {
open_writable_with(path, None)
}
pub fn open_writable_with(path: &Path, compression: Option<Compression>) -> Result<Store, String> {
if path.exists() {
if compression.is_some() {
return Err(format!(
"store {} already exists; its persisted compression policy applies \
(drop --compression/--shuffle)",
path.display()
));
}
open_store(path, false).map_err(|e| e.to_string())
} else {
match compression {
Some(c) => Store::create_with_compression(Some(path), false, c),
None => create_store(Some(path), false),
}
.map_err(|e| e.to_string())
}
}