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]] [[package]]
name = "markov" name = "markov"
version = "0.3.1" version = "0.3.2"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"futures", "futures",

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

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

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

Loading…
Cancel
Save