|
|
|
@ -45,16 +45,19 @@ pub async fn save_now(state: &State) -> io::Result<()>
|
|
|
|
|
async fn save_now_to(chain: &Chain<String>, to: impl AsRef<Path>) -> io::Result<()>
|
|
|
|
|
{
|
|
|
|
|
debug!("Saving chain to {:?}", to.as_ref());
|
|
|
|
|
let file = OpenOptions::new()
|
|
|
|
|
let mut file = OpenOptions::new()
|
|
|
|
|
.write(true)
|
|
|
|
|
.create(true)
|
|
|
|
|
.truncate(true)
|
|
|
|
|
.open(to).await?;
|
|
|
|
|
let chain = serde_cbor::to_vec(chain).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
|
|
|
|
|
|
|
|
|
let mut file = AsyncWriteCompressor::new(file, PreferencesBuilder::new()
|
|
|
|
|
.compression_level(lz4f::CLEVEL_HIGH).build())?;
|
|
|
|
|
file.write_all(&chain[..]).await?;
|
|
|
|
|
{
|
|
|
|
|
let mut file = AsyncWriteCompressor::new(&mut file, PreferencesBuilder::new()
|
|
|
|
|
.compression_level(lz4f::CLEVEL_HIGH).build())?;
|
|
|
|
|
file.write_all(&chain[..]).await?;
|
|
|
|
|
file.flush().await?;
|
|
|
|
|
file.shutdown().await?;
|
|
|
|
|
}
|
|
|
|
|
file.flush().await?;
|
|
|
|
|
file.shutdown().await?;
|
|
|
|
|
Ok(())
|
|
|
|
@ -94,6 +97,7 @@ pub async fn load(from: impl AsRef<Path>) -> io::Result<Chain<String>>
|
|
|
|
|
let mut whole = Vec::new();
|
|
|
|
|
let mut file = AsyncReadDecompressor::new(file)?;
|
|
|
|
|
tokio::io::copy(&mut file, &mut whole).await?;
|
|
|
|
|
whole.flush().await?;
|
|
|
|
|
serde_cbor::from_slice(&whole[..])
|
|
|
|
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))
|
|
|
|
|
}
|
|
|
|
|