Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4fd3dde

Browse files
committedMay 11, 2019
add zstd stream stubs
1 parent ce66a92 commit 4fd3dde

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
 

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bytes = "0.4.12"
1111
flate2 = "1.0.7"
1212
futures-preview = "0.3.0-alpha.15"
1313
pin-project = "0.3.2"
14+
zstd = "0.4"
1415

1516
[dev-dependencies]
1617
proptest = "0.9.3"

‎src/stream/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pub mod brotli;
44
pub mod deflate;
55
pub mod gzip;
66
pub mod zlib;
7+
pub mod zstd;

‎src/stream/zstd.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::{
2+
io::Result,
3+
mem,
4+
pin::Pin,
5+
task::{Context, Poll},
6+
};
7+
8+
use bytes::{Bytes, BytesMut};
9+
use futures::{ready, stream::Stream};
10+
use pin_project::unsafe_project;
11+
use zstd::stream::raw::{Decoder, Encoder, Operation, Status};
12+
13+
#[derive(Debug)]
14+
enum State {
15+
Reading,
16+
Writing(Bytes),
17+
Flushing,
18+
Done,
19+
Invalid,
20+
}
21+
22+
#[unsafe_project(Unpin)]
23+
pub struct ZstdStream<S: Stream<Item = Result<Bytes>>> {
24+
#[pin]
25+
inner: S,
26+
state: State,
27+
output: BytesMut,
28+
encoder: Encoder,
29+
}
30+
31+
impl<S: Stream<Item = Result<Bytes>>> Stream for ZstdStream<S> {
32+
type Item = Result<Bytes>;
33+
34+
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes>>> {
35+
unimplemented!()
36+
}
37+
}
38+
39+
40+
#[unsafe_project(Unpin)]
41+
pub struct DecompressedZstdStream<S: Stream<Item = Result<Bytes>>> {
42+
#[pin]
43+
inner: S,
44+
state: State,
45+
output: BytesMut,
46+
decoder: Decoder,
47+
}
48+
49+
impl<S: Stream<Item = Result<Bytes>>> Stream for DecompressedZstdStream<S> {
50+
type Item = Result<Bytes>;
51+
52+
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes>>> {
53+
unimplemented!()
54+
}
55+
}

0 commit comments

Comments
 (0)
Please sign in to comment.