mirror of
https://github.com/gyscos/zstd-rs
synced 2024-10-18 13:52:51 +00:00
encoder: add AsyncWrite
implementation
This commit is contained in:
parent
6c915474b6
commit
3c3ab356a8
|
@ -16,6 +16,8 @@ travis-ci = { repository = "gyscos/zstd-rs" }
|
|||
[dependencies]
|
||||
libc = "0.2"
|
||||
zstd-sys = { path="zstd-sys", version = "1.1.5-a", default-features = false }
|
||||
tokio-io = { version = "0.1", optional = true }
|
||||
futures = { version = "0.1", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
clap = "2.6.0"
|
||||
|
@ -24,3 +26,4 @@ clap = "2.6.0"
|
|||
default = ["legacy"]
|
||||
legacy = ["zstd-sys/legacy"]
|
||||
bindgen = ["zstd-sys/bindgen"]
|
||||
tokio = ["tokio-io", "futures"]
|
||||
|
|
|
@ -31,6 +31,13 @@ pub mod stream;
|
|||
pub mod block;
|
||||
pub mod dict;
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
#[macro_use]
|
||||
extern crate tokio_io;
|
||||
#[cfg(feature = "tokio")]
|
||||
extern crate futures;
|
||||
|
||||
|
||||
use std::ffi::CStr;
|
||||
|
||||
use std::io;
|
||||
|
|
|
@ -4,6 +4,11 @@ use parse_code;
|
|||
use std::io::{self, Write};
|
||||
use zstd_sys;
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
use futures::Poll;
|
||||
#[cfg(feature = "tokio")]
|
||||
use tokio_io::AsyncWrite;
|
||||
|
||||
struct EncoderContext {
|
||||
s: *mut zstd_sys::ZSTD_CStream,
|
||||
}
|
||||
|
@ -328,6 +333,14 @@ impl<W: Write> Write for Encoder<W> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
impl <W: AsyncWrite> AsyncWrite for Encoder<W> {
|
||||
fn shutdown(&mut self) -> Poll<(), io::Error> {
|
||||
try_nb!(self.do_finish());
|
||||
self.writer.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Encoder;
|
||||
|
|
Loading…
Reference in a new issue