Skip to content

Commit 21f3b0d

Browse files
committed
Deprecate stream and add migration docs
1 parent 709a859 commit 21f3b0d

File tree

9 files changed

+169
-13
lines changed

9 files changed

+169
-13
lines changed

Diff for: Cargo.lock

+57-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ all = ["all-implementations", "all-algorithms"]
2222
all-implementations = ["futures-io", "stream", "tokio-02", "tokio-03", "tokio"]
2323
all-algorithms = ["brotli", "bzip2", "deflate", "gzip", "lzma", "xz", "zlib", "zstd"]
2424

25-
# implementations
26-
stream = ["bytes-05"]
27-
2825
# algorithms
2926
deflate = ["flate2"]
3027
gzip = ["flate2"]
@@ -34,6 +31,7 @@ zlib = ["flate2"]
3431
zstd = ["libzstd", "zstd-safe"]
3532

3633
# deprecated
34+
stream = ["bytes-05"]
3735
futures-bufread = ["futures-io"]
3836
futures-write = ["futures-io"]
3937

@@ -62,12 +60,16 @@ futures-test = "0.3.5"
6260
ntest = "0.3.3"
6361
timebomb = "0.1.2"
6462
bytes-05 = { package = "bytes", version = "0.5.0" }
63+
bytes-06 = { package = "bytes", version = "0.6.0" }
6564
bytes = "1.0.0"
6665
tokio-02 = { package = "tokio", version = "0.2.21", default-features = false, features = ["io-util", "stream", "macros", "io-std"] }
6766
tokio-03 = { package = "tokio", version = "0.3.0", default-features = false, features = ["io-util", "stream"] }
6867
tokio = { version = "1.0.0", default-features = false, features = ["io-util"] }
69-
tokio-util-04 = { package = "tokio-util", version = "0.4.0", default-features = false, features = ["io"] }
70-
tokio-util-06 = { package = "tokio-util", version = "0.6.0", default-features = false, features = ["io"] }
68+
tokio-util-03 = { package = "tokio-util", version = "0.3.0", default-features = false, features = ["codec"] }
69+
tokio-util-04 = { package = "tokio-util", version = "0.4.0", default-features = false, features = ["codec", "io"] }
70+
tokio-util-05 = { package = "tokio-util", version = "0.5.0", default-features = false, features = ["codec", "io"] }
71+
tokio-util-06 = { package = "tokio-util", version = "0.6.0", default-features = false, features = ["codec", "io"] }
72+
futures_codec = { version = "0.4.1", default-features = false }
7173

7274
[[test]]
7375
name = "brotli"

Diff for: src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
)]
4848
#![cfg_attr(
4949
feature = "stream",
50-
doc = "[`stream`] | [`futures::stream::Stream`](futures_core::stream::Stream)`<Item = `[`std::io::Result`]`<`[`bytes_05::Bytes`]`>>`"
50+
doc = "[`stream`] | (*deprecated*, see [`async-compression:stream`](crate::stream) docs for migration)"
5151
)]
5252
#![cfg_attr(
5353
not(feature = "stream"),
54-
doc = "`stream` (*inactive*) | `futures::stream::Stream<Item = std::io::Result<bytes::Bytes>>`"
54+
doc = "`stream` (*inactive*) | (*deprecated*, see `async-compression::stream` docs for migration)"
5555
)]
5656
#![cfg_attr(
5757
feature = "tokio-02",

Diff for: src/stream/mod.rs

+95
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,101 @@
77
//! between chunks of data from the underlying stream and the resulting compressed/decompressed
88
//! stream, the encoders and decoders will buffer the incoming data and choose their own boundaries
99
//! at which to yield a new item.
10+
//!
11+
//! # Deprecation Migration
12+
//!
13+
//! This feature and module was deprecated because it's choosing one point in a large solution
14+
//! space of "stream of byte chunks" to represent an IO data stream, and the conversion between
15+
//! these solutions and standard IO data streams like `futures::io::AsyncBufRead` /
16+
//! `tokio::io::AsyncBufRead` should be zero-cost.
17+
//!
18+
//! ```rust
19+
//! use bytes_05::Bytes;
20+
//! use futures::{stream::Stream, TryStreamExt};
21+
//! use std::io::Result;
22+
//!
23+
//!
24+
//! /// For code that looks like this, choose one of the options below to replace it
25+
//! fn from(
26+
//! input: impl Stream<Item = Result<bytes_05::Bytes>>,
27+
//! ) -> impl Stream<Item = Result<bytes_05::Bytes>> {
28+
//! #[allow(deprecated)]
29+
//! async_compression::stream::GzipEncoder::new(input)
30+
//! }
31+
//!
32+
//! /// Direct replacement with `tokio` v0.2 and `bytes` v0.5 using `tokio-util` v0.3
33+
//! fn tokio_02_bytes_05(
34+
//! input: impl Stream<Item = Result<bytes_05::Bytes>>,
35+
//! ) -> impl Stream<Item = Result<bytes_05::Bytes>> {
36+
//! tokio_util_03::codec::FramedRead::new(
37+
//! async_compression::tokio_02::bufread::GzipEncoder::new(
38+
//! tokio_02::io::stream_reader(input),
39+
//! ),
40+
//! tokio_util_03::codec::BytesCodec::new(),
41+
//! ).map_ok(|bytes| bytes.freeze())
42+
//! }
43+
//!
44+
//! /// Upgrade replacement with `tokio` v0.3 and `bytes` v0.5 using `tokio-util` v0.4
45+
//! fn tokio_03_bytes_05(
46+
//! input: impl Stream<Item = Result<bytes_05::Bytes>>,
47+
//! ) -> impl Stream<Item = Result<bytes_05::Bytes>> {
48+
//! tokio_util_04::codec::FramedRead::new(
49+
//! async_compression::tokio_03::bufread::GzipEncoder::new(
50+
//! tokio_util_04::io::StreamReader::new(input),
51+
//! ),
52+
//! tokio_util_04::codec::BytesCodec::new(),
53+
//! ).map_ok(|bytes| bytes.freeze())
54+
//! }
55+
//!
56+
//! /// Upgrade replacement with `tokio` v0.3 and `bytes` v0.6 using `tokio-util` v0.5
57+
//! fn tokio_03_bytes_06(
58+
//! input: impl Stream<Item = Result<bytes_06::Bytes>>,
59+
//! ) -> impl Stream<Item = Result<bytes_06::Bytes>> {
60+
//! tokio_util_05::codec::FramedRead::new(
61+
//! async_compression::tokio_03::bufread::GzipEncoder::new(
62+
//! tokio_util_05::io::StreamReader::new(input),
63+
//! ),
64+
//! tokio_util_05::codec::BytesCodec::new(),
65+
//! ).map_ok(|bytes| bytes.freeze())
66+
//! }
67+
//!
68+
//! /// Upgrade replacement with `tokio` v1.0 and `bytes` v1.0 using `tokio-util` v0.6
69+
//! fn tokio_bytes(
70+
//! input: impl Stream<Item = Result<bytes::Bytes>>,
71+
//! ) -> impl Stream<Item = Result<bytes::Bytes>> {
72+
//! tokio_util_06::codec::FramedRead::new(
73+
//! async_compression::tokio::bufread::GzipEncoder::new(
74+
//! tokio_util_06::io::StreamReader::new(input),
75+
//! ),
76+
//! tokio_util_06::codec::BytesCodec::new(),
77+
//! ).map_ok(|bytes| bytes.freeze())
78+
//! }
79+
//!
80+
//! /// What if you didn't want anything to do with `bytes`, but just a `Vec<u8>` instead?
81+
//! fn futures_vec(
82+
//! input: impl Stream<Item = Result<Vec<u8>>> + Unpin,
83+
//! ) -> impl Stream<Item = Result<Vec<u8>>> {
84+
//! use futures::io::AsyncReadExt;
85+
//!
86+
//! futures::stream::try_unfold(
87+
//! async_compression::futures::bufread::GzipEncoder::new(input.into_async_read()),
88+
//! |mut encoder| async move {
89+
//! let mut chunk = vec![0; 8 * 1024];
90+
//! let len = encoder.read(&mut chunk).await?;
91+
//! if len == 0 {
92+
//! Ok(None)
93+
//! } else {
94+
//! chunk.truncate(len);
95+
//! Ok(Some((chunk, encoder)))
96+
//! }
97+
//! })
98+
//! }
99+
//! ```
100+
101+
#![deprecated(
102+
since = "0.3.8",
103+
note = "See `async-compression::stream` docs for migration"
104+
)]
10105

11106
#[macro_use]
12107
mod macros;

Diff for: tests/proptest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ macro_rules! tests {
107107
($variant:ident) => {
108108
mod $variant {
109109
#[cfg(feature = "stream")]
110+
#[allow(deprecated)]
110111
mod stream {
111112
use crate::utils::{algos::$variant::{stream, sync}, InputStream};
112113
use proptest::{prelude::{any, ProptestConfig}, proptest};

Diff for: tests/utils/algos.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ macro_rules! algos {
5656
pub mod sync { $($tt)* }
5757

5858
#[cfg(feature = "stream")]
59+
#[allow(deprecated)]
5960
pub mod stream {
6061
pub use async_compression::stream::{$decoder as Decoder, $encoder as Encoder};
6162
pub use crate::utils::impls::stream::to_vec;

Diff for: tests/utils/impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub mod futures {
7979
}
8080

8181
#[cfg(feature = "stream")]
82+
#[allow(deprecated)]
8283
pub mod stream {
8384
use crate::utils::{block_on, pin_mut, Result};
8485
use bytes_05::Bytes;

Diff for: tests/utils/test_cases.rs

+1
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ macro_rules! test_cases {
448448
($variant:ident) => {
449449
mod $variant {
450450
#[cfg(feature = "stream")]
451+
#[allow(deprecated)]
451452
mod stream {
452453
mod compress {
453454
use crate::utils::{

Diff for: tests/xz.rs

+4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ fn stream_multiple_members_with_padding() {
2929

3030
let input = InputStream::from(vec![compressed]);
3131

32+
#[allow(deprecated)]
3233
let mut decoder = stream::Decoder::new(input.bytes_05_stream());
34+
#[allow(deprecated)]
3335
decoder.multiple_members(true);
3436
let output = stream::to_vec(decoder);
3537

@@ -50,7 +52,9 @@ fn stream_multiple_members_with_invalid_padding() {
5052

5153
let input = InputStream::from(vec![compressed]);
5254

55+
#[allow(deprecated)]
5356
let mut decoder = stream::Decoder::new(input.bytes_05_stream());
57+
#[allow(deprecated)]
5458
decoder.multiple_members(true);
5559

5660
assert!(block_on(decoder.next()).unwrap().is_err());

0 commit comments

Comments
 (0)