File tree 3 files changed +57
-0
lines changed
3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ bytes = "0.4.12"
11
11
flate2 = " 1.0.7"
12
12
futures-preview = " 0.3.0-alpha.15"
13
13
pin-project = " 0.3.2"
14
+ zstd = " 0.4"
14
15
15
16
[dev-dependencies ]
16
17
proptest = " 0.9.3"
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ pub mod brotli;
4
4
pub mod deflate;
5
5
pub mod gzip;
6
6
pub mod zlib;
7
+ pub mod zstd;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments