FUCK FUCK YOU FUCK

serve
Avril 4 years ago
parent 8b5b753e9b
commit c5993b54e9
Signed by: flanchan
GPG Key ID: 966FE03CC0E0B199

2
Cargo.lock generated

@ -605,7 +605,7 @@ dependencies = [
[[package]]
name = "markov"
version = "0.3.1"
version = "0.3.2"
dependencies = [
"cfg-if 1.0.0",
"futures",

@ -1,6 +1,6 @@
[package]
name = "markov"
version = "0.3.1"
version = "0.3.2"
description = "Generate string of text from Markov chain fed by stdin"
authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018"

@ -3,7 +3,7 @@ markov:
strip target/release/markov
install:
rc-service markov stop
-rc-service markov shutdown && sleep 0.6
cp -f target/release/markov /usr/local/bin/markov
rc-service markov start

@ -45,18 +45,21 @@ 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()
{
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))
}

Loading…
Cancel
Save