async-compression 0.4.41

Adaptors between compression crates and Rust's modern asynchronous IO types.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
7�0�~{�?��
0�0�0����D�)�\����2;�[����i�n5�����h��َ��pwHĢ�T6�U���#*,&���H(���A�Q �q@���JT�*d!          let input = InputStream::new(vec![]);

 }

            mod write {
                mod com00)]
                    fn multiple_members() {
              assert_eq!(trailer, &[7, 8, 9, 10][..meout(1000)]
                    fn trailer() {
  
                        let decod result = read::poll_read(encoder, &mut output);
 est::timeout(1000)]
                    fn empty()
        mod $impl {
            mod bufread {
    {
        limited::Limited::new(self, limit)
    _cases;

pub mod algos;
pub mod impls;

pub use seure = "tokio")]
mod tokio_ext;
mod track_closed;
m      ready!(self.as_mut().do_poll_flush(cx))?;

 ?;
    decoder.shutdown().await?;
    Ok(decoder.ihutdown`

#[tokio::main(flavor = "current_thread")th the following command in a terminal:
//!
//! ``     &mut self.buffer.as_mut()[self.index..]
    },
    index: usize,
}

impl<B: AsRef<[u8]>> Partiaync>() {}

#[derive(Debug, Default)]
pub struct Pacompress.total_out();

        let status =
      ,
}

impl FlateDecoder {
    pub(crate) fn new(zli_args!("{}/{}", self.buffered, self.buf.len()),
  s.buffered += len;
            Poll::Ready(Ok(len)         }
        }

        if *this.written > 0d])
            {
                Poll::Pending =>ufWriter` with the specified buffersyncWrite;

const DEFAULTe]
mod utils;

test_cases!(deflate);
// Originally  fn produce(self: Pin<&mut Self>, amt: usize);
}
his function is a lower-level call. It needs nderlying IO when possible.
    ///
    /// This ffull.
    ///
    /// On success, returns `Poll::R output.advance(len);
        Ok(bytes_left == 0)
tten_mut())?;
        input.advance(status.bytes_rate) fn new_with_dict(dictionary: &[u8]) -> io::Reshared::Unshared, util::PartialBuffer};
use libzstader(_) | State::Footer(_) | State::Done => returnlt());
        self.header = Header::default();
  ter(footer) => {
                    footer.copy_u.state {
                State::Header(parser) =>   }
    }

    fn process<I: AsRef<[u8]>, O: AsRef
    let crc_sum = crc.sum().to_le_bytes();
    le2::Crc;

#[derive(Debug)]
enum State {
    Header(, level),
        }
    }
}

impl Encode for LzmaElBuffer::new(&[][..]), output, Action::Finish)? {
othing much to report.
            Status::Ok => u
        Ok(status)
    }
}

impl Encode for BzEnc /// equivalent to using the default value of 30.
r over a wide range of
    /// circumstances.
    
    /// a factor of three, but always behaves reader {
    /// Creates a new stream prepared for coerwise we'll just keep writing
        // out sync AsRef<[u8]> + AsMut<[u8]>>,
        flush: FlushCw(level, zlib_header),
            flushed: true,
d::io::Result;

#[derive(Debug)]
pub struct LzmaDebytes, so it must be invalid
            // paddin*count == 0 {
                    *count = 4;
    Kind, Result};

#[derive(Debug)]
pub struct XzDeco {
    pub(crate) fn new(level: Compression) -> Seut Self>, amt: usize) {
        self.project().0.c         }
                Poll::Ready(Ok(0))
    er, eof } = Pin::into_inner(self);
        (Pin::n inner: R,
    eof: bool,
}

impl<R: Unpin> TrackEa from the given stream
                /// and emState::Encoding => {
                    if self.i                        true
           }

                State::Encoding => self.iitten().is_empty() {
                return Ok(()).state {
                State::Header(header) => ty(8);

        output.extend(&self.crc.sum().to_lx08, 0, 0, 0, 0, 0, level_byte, 0xff]
}

impl Gzip   crc: Crc,
    state: State,
}

fn header(level://! Implementations for IO traits exported by [`fute
            /// when reaching the end of a comp// This structure implements an [`AsyncRead`](tokiate) use self::{decoder::XzDecoder, encoder::XzEnc    match status {
            Status::Ok | Status    pub fn new(format: Xz2FileFormat, level: u32) fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult               }

                State::Crc(data) e(len) = memchr::memchr(0, input.unwritten()) {
                  self.state = State::Comment(<_>::d                if !self.header.flags.extra {
    t self.state {
                State::Fixed(data) ErrorKind::InvalidData, "Invalid gzip header"));
 {
        if input[0..3] != [0x1f, 0x8b, 0x08] {
  {
    ascii: bool,
    crc: bool,
    extra: bool
impl<R: AsyncBufRead, E: Encode> AsyncRead for En  #[derive(Debug)]
    pub struct Encoder<R, E: Enite::pin_project;
use tokio::io::AsyncWrite;

#[destruct("BrotliDecoder")
            .field("decomp),
            BrotliResult::NeedsMoreInput => Err? {
            BrotliResult::ResultSuccess | Brot_len,
            out_buf,
            &mut 0,
          let mut out_buf = output.unwritten_mut();

.
    state: Box<BrotliState<StandardAlloc, Standaression parameters.
        pub fn job_size(value:hreads and `flush` pushes bytes through the compreionary (default: true).
        pub fn dict_id_flau32) -> Self {
            Self(LdmHashRateLog(valSelf {
            Self(EnableLongDistanceMatchinghing mode to look for and emit long-distance refer    }

        /// Number of search attempts (as antation](https://facebook.github.io/zstd/zstd_manuty) => quality.try_into().unwrap_or(0).min(9),
   bzstd::compression_level_range().into_inner();
    fn into_flate2(self) -> flate2::Compression {
   ch self {
            Self::Fastest => fastest,
  this depends on the algorithm chosen
    /// and tressed with.
#[non_exhaustive]
#[derive(Clone, Copkio")]
pub mod tokio;

mod unshared;
mod util;

#[   doc = "`zlib` | [`ZlibEncoder`](?search=ZlibEncarch=LzmaEncoder), [`LzmaDecoder`](?search=LzmaDec | [`GzipEncoder`](?search=GzipEncoder), [`GzipDec(?search=BzEncoder), [`BzDecoder`](?search=BzDecodcWrite`"
)]
//!

//! ## Compression algorithm
//!
ion, `#![rustfmt::skip::attributes(cfg_attlection of algorithms
//!  `all-algorithms` | Acti which can each be individually selected via Cargo      }
    }
}
//! Adaptors between compression c  #[derive(Debug)]
    pub struct Decoder<R, D: DeotliEncoderOperation::BROTLI_OPERATION_FINISH,
   coderOperation::BROTLI_OPERATION_PROCESS,
     n);

        Ok(())
    }
}

impl Encode for Brotl        &mut None,
            &mut |_, _, _, _| (b(crate) fn new(params: BrotliEncoderParams) -> SeParams,
    encode::{
        BrotliEncoderCompres

        algos!(@algo xz ["xz"] XzDecoder XzEncodhe dictionary used must be the same as the one
      })
            }
        }
        { @dec
     on.
            ///
            /// # Errors
     ::new_with_params(level.into_zstd(), params),
      //
            // TODO: remove panic note on nex and parameters, which
            /// will read uinner,
                        crate::codec::ZlibE    algos!(@algo gzip ["gzip"] GzipDener,
                        crate::codec::Deflate     algos!(@algo bzip2 ["bzip2"] BzDecoder BzEncoBrotliEncoder::new(level.into_brotli(params)),
   t!("A ", $algo_s, " encoder, or compressor.")]
   
algos!(futures::bufread<R>);
macro_rules! algos {rue)
    }
}
//! Types which operate over [`AsyncBushOk => unreachable!(),

            // THe Run a      let prior_in = self.decompress.total_in();
 ompress.total_out()
        )
    }
}

impl BzDeco::Decode, util::PartialBuffer};
use std::fmt;
use       inner: crate::tokio::write::Decoder<W, crate=> Err(std::io::Error::new(
                std::i) -> Result<()> {
        *self = Self::new();
   der {
    stream: Stream,
}

impl Debug for Xz2Decnts an [`AsyncWrite`](tokio::io::AsyncWrite) inter }
}
#[macro_use]
mod utils;

test_cases!(bzip2);
next = Pin::new(&mut self.inner).poll_flush(cx);
 tokio::io::AsyncWrite for InterleavePending<W> {
 self::{decoder::BzDecoder, encoder::BzEncoder};
usmember/frame and expect either EOF or another
    ssed stream.
            pub fn new(read: R) -> $nyncRead) interface and will
            /// read c       Pin::new(&mut this.reader).consume(i);
      let buffer = ready!(Pin::new(&mut this.reader).pwriter: &'a mut W,
    amt: u64,
}

impl<R, W> Futopy_buf<R, W>(reader: R, writer: &mut W) -> CopyBuin::new(&mut self.inner).poll_write(cx, buf)
    } match Pin::new(&mut self.inner).poll_close(cx) {
Write for TrackClosed<W> {
    fn poll_write(mut s}
    }

    pub fn is_closed(&self) -> bool {
   tdown before finishing input",
            )))
   ck_on(decoder.read_to_end(&mut output)).is_err());t input = InputStream::from(vec![compressed]);

  [][..]);

    let input = InputStream::from(vec![c)]
use utils::{algos::xz::sync, InputStream};

#[cten to and should
    /// be sent. As such, this fs buffer, so they should be
    /// written out tok(buf))`.
    ///
    /// If the buffer is full anrs {
                            this.decoder.rein              }

                State::Flushing =                     *this.multiple_members = fals) {
        self.multiple_members = enabled;
    }e> Decoder<R, D> {
    pub fn new(reader: R, decod(Debug)]
enum State {
    Decoding,
    Flushing,
 whether the end of the stream has been read
    f buffers are flushed
    fn flush(&mut self, outpu)]
pub(crate) use self::zlib::{ZlibDecoder, ZlibEnpub(crate) use self::flate::{FlateDecoder, FlateEn "lzma")]
mod lzma;
#[cfg(feature = "xz")]
mod xz;f_write::AsyncBufWrite,
    buf_writer::BufWriter, {
    /// Seek to the offset, in bytes, in the unt::Result {
        f.debug_struct("BufWriter")
  )?;
        self.project().inner.poll_close(cx)
  .*this.buffered + len].copy_from_slice(&buf[..len]t this = self.as_mut().project();
        if buf.lthe underlying writer.
    ///
    /// Note that aReady(ret)
        } else if *this.buffered == 0 {.written += n,
                Poll::Ready(Err(e))ed])
            {
                Poll::Pending =pacity.
    pub fn with_capacity(cap: usize, innertures_io::{AsyncSeek, AsyncWrite, SeekFrom};
use p
// the `AsyncBufWrite` impl can access its intern   }
                }

                mod decompity(
                                    input,
  ).as_ref(),
                            |input| {
te::Encoder::with_quality(input, Level::Best)),
  ress {
                    use crate::utils::{
                let output = read::to_vec(decoder);

          sync::compress(&[1, 2, 3, 4, 5, 6]),
         let trailer = read::to_vec(reader)    let output = bufread::decompress(&mut reader);::timeout(1000)]
                    fn zeros() {
         let compressed = sync::compress(&[]);

  ::$variant::{
                            sync,
                              Level::Precise(0),
   am()),
                            Level::Best,
  ::compress(bufread::from(&one_to_six_stream()));
 
                        let mut output = [];

                    let mut input: &[u8] = &[];
     tokio::io::AsyncWrite> AsyncWriteTestExt for T {}
ending;
mod limited;

pub use copy_buf::copy_buf;
:{future::Future, io::Result, iter::FromIterator, erent tests use a different subset of functions

mlf.as_mut().project().state {
            *self.asn compress(in_data: &[u8]) -> Result<Vec<u8>> {
  tures="tokio,zlib"
//! "example"
//! ```

use  $ cargo run --example zlib_tokio_write --features = std::cmp::min(self.unwritten().len(), other.unwf.index]
    }

    pub(crate) fn unwritten(&self) }
    }
}
pub fn _assert_send<T: Send>() {}
pub fw(&[][..]),
            output,
            FlushDsMut<[u8]>>,
        flush: FlushDecompress,
    )ress, Status};

#[derive(Debug)]
pub struct FlateD            .field(
                "buffer",
    ush_buf(cx))?;
        self.project().inner.poll_st len = min(this.buf.len() - *this.buffered, buf.lwere Pending, so our waker was already queued
    t W> {
        self.project().inner
> *this.written += n,
                Err(e) => {
:Ready(ret)
        } else {
            ret?;
           }
                Poll::Ready(Ok(n)) => *t: vec![0; cap].into(),
            written: 0,
   Self::with_capacity(DEFAULT_BUF_SIZE, inner)
    } efficient
// with those methods.

use super::Asyn     ready!(self.project().writer.as_mut().poll_cle::Finishing | State::Done => panic!("Flush after ;

use crate::{
    codec::Encode,
    futures::wrbuf` method to
    /// function properly. This fun `Poll::Pending` and
    /// arranges for the currcrate) trait AsyncBufWrite {
    /// Attempt to ret_buf)?;
        let len = out_buf.as_slice().len(      .get_mut()
            .run_on_buffers(inputcoder = Decoder::with_dictionary(dictionary)?;
        "unexpected end of file",
            ))
     flushed all the data out before we get here
     Header(_) | State::Footer(_) | State::Done => retuimpl Decode for GzipDecwritten().is_empty() {
                        che self.state = State::Footer(vec![0; 8].into())
   r<I>, &mut PartialBuffer<O>) -> Result<bool>,
    
    if bytes_read != input[4..8] {
  
}

fn check_footer(crc: &Crc, input: &[u8]) -> Re codec::{
        gzip::header::{self, Header},
  >,
    ) -> Result<bool> {
        // Flush on LZM   inner: crate::codec::Xz2Encoder,
}

impl LzmaEn  // Decompression went fine, nothing much to repoBuffer::new(&[][..]), output, Action::Flush)? {
  atch self.encode(input, output, Action::Run)? {
  unwritten(), output.unwritten_mut(), action)
     u8]> + AsMut<[u8]>>,
        action: Action,
    )rd
    /// algorithm will expend before resorting presented with worst case, highly repetitive, inpu       write!(
            f,
            "BzEncoduse]
mod decoder;
#[macro_use]
mod encoder;
use crd_len = output.written().len();
            self.e    // We need to keep track of whether we've alreOk => Ok(()),
            Status::StreamEnd => unren_mut(), flush)?;

        input.advance((self.coesult};

use flate2::{Compress, Compression, Flush   inner: crate::codec::Xz2Decoder,
}

impl LzmaDe      "stream padding was not a multiple of 4 bytelet Some(ref mut count) = self.skip_padding {
    padding = Some(4);
        self.inner.reinit()
   er: crate::codec::FlateEncoder::new(level, false),cBufRead for TrackEof<R> {
    fn poll_fill_buf(sePoll::Ready(Ok(())) => {
                if buf.fi       }
                Poll::Ready(Ok(buf))
    text) -> Poll<Result<&[u8]>> {
        let (inner,yncRead + Unpin> futures::io::AsyncRead for TrackE Self { inner, eof: false }
    }

    pub fn proj           }
        }

        impl<$inner: futurAsyncBufRead> $name<$inner> {
            $(
     from an underlying stream and emit a stream of comitten().is_empty() {
                return Ok(fal    self.state = State::Footer(self.footer().into(      }

                State::Done => true,
                  output.copy_unwritten_from(&mut *fooState::Done => panic!("encode after complete"),
                    self.state = State::Encoding;
  level).into()),
        }
    }

    fn footer(&mu        0x02
    } else if level.level() <= CompreBuffer<Vec<u8>>),
    Encoding,
    Footer(Partiallt<usize>> {
        let limit = self.limit;
     o`](::futures_io).

pub mod bufread;
pub mod write<'_>,
                buf: &mut tokio::io::ReadBuf /// compressed member/frame to follow it in the sethods)*)*

            /// Configure multi-member    inner: crate::tokio::bufread::Decoder<R, cratener:ident> $({ $($inherent_methods:tt)* })*) => {
[], output.unwritten_mut(), Action::SyncFlush)?;

out() as usize - previous_out);

 elf.stream.total_in() as usize - previous_in);
   :new_lzma_encoder(&LzmaOptions::new_preset(level).            panic!("parser used after done");
    f.header.flags.crc {
              input.advance(input.unwritten().len());
                    self.state = State::Crc(<_>::d:default());
                        continue;
               }

                State::Extra(data)                 self.state = State::Filename(<_>::AsRef<[u8]>>,
    ) -> Result<Option<Header>> {
      Ok(Header { flags })
    }
}

impl Parser {
  e,
    header: Header,
}

impl Header {
    fn parol,
    filename: bool,
    comment: bool,
}

#[de     let mut output = PartialBuffer::new(buf);
   ume(len);
                        State::Encoding
t);
                        this.encoder.encode(&m,
    }
}

impl<R: AsyncBufRead, E: Encode> Encodeelf.project().writer.as_mut().poll_shutdown(cx))?;
    }

    fn do_poll_shutdown(self: alBuffer::new(output);

            let done = matncoding => {
                    this.encoder.encoive(Debug)]
    pub struct Encoder<W, E: Encode> {of,
                "reached unexpected EOF",
    sMoreOutput => ,
            BrotliResult::NeedsMoreOutput | Brot
            }
            status => status,
       let status = match BrotliDecompressStream(
     liState` is very large (over 2kb) which is why we'stream::raw::CParameter {
            self.0
     :with_quality_and_params()` calls.
        //
    // Emit a dictionary ID when using a custom dictio power of two)
        pub fn ldm_hash_rate_log(va        pub fn enable_long_distance_matching(valueength modifier
        pub fn target_length(value:ue: u32) -> Self {
            Self(HashLog(value)ession parameter for zstd. This is a stable wrappe Self::Default => libzstd::DEFAULT_COMPRESSION_LEVelf) -> i32 {
        let (fastest, best) = libzst        let best = flate2::Compression::best();

 ::Compression::new(
                quality
      g it.
    /// Qualities are implicitly clamped to ession algorithm.
    Default,
    /// Precise quarn(
    missing_docs,
    rust_2018_idioms,
    mi   doc = "`zstd` | [`ZstdEncoder`](?search=ZstdEnce = "xz"),
    doc = "`xz` (*inactive*) | `XzEncodoc = "`deflate` | [`DeflateEncoder`](?search=Deflac = "`brotli` (*inactive*) | `BrotliEncoder`, `Broable choices, these determine which types will be fg_attr)]` should do it, but
// that's unstable
#!s that have corresponding top-level modules:
//!

tes and Rust's modern asynchronous IO types.
//!

utput = PartialBuffer::new(buf.initialize_unfilled> State::Done,

                State::Next => {
                       if *this.multiple_members {
f the reader
                        // has return      self.reader
    }

    pub fn mulf>) -> Pin<&mut R> {
        self.project().readert;
use tokio::io::{AsyncBufRead, AsyncRead, ReadBuk(BrotliEncoderIsFinished(&self.state) == 1)
    }    Ok(BrotliEncoderHasMoreOutput(&self.state) == Error::new(ErrorKind::Other, "brotli error"));
           out_buf,
            &mut output_len,
    iEncoderStateStruct<StandardAlloc>,
}

impl BrotlirKind, Result},
};

use brotli::enc::{
    backwar inner,
                        crate::codec::Lzma  crate::codec::ZstdDecoder::new_with_dict(diction   /// be present during decompression. The dictiohe given stream and emit an
            /// uncompReturns error when `dictionary` is not valid.
    ::Level, params: &[crate::zstd::CParameter]) -> Se /// the `zstdmt` crate feature is _not_ enabled.
pressed data from the given stream and emit a compbEncoder <$inner>
        { @enc
         algos!(@algo zlib ["zlib"] ZlibDecoder ZlibEnc;

        algos!(@algo deflate ["deflate"] Deflatcodec::BzEncoder::new(level.into_bzip2(), 0),
    lgos!(@algo brotli ["brotli"] BrotliDecoder Brotlithods)* }
        }
    };

    ($($mod:ident)::+    (@algo $algo:ident [$algo_s:expr] $decoder:idend`](futures_io::AsyncBufRead) streams, both encodede(&mut PartialBuffer::new(&[][..]), output)?;

  ut.
            Status::StreamEnd => Ok(true),

  .advance((self.decompress.total_out() - prio::Error::new(std::io::ErrorKind::Other, e))?;

 s: Decompress,
}

impl fmt::Debug for Bz;
    }
}
mod decoder;
mod encoder;
mod header;

p            }

            fn poll_shutdown(
     x, buf)
            }

            fn poll_flush(
o_inner()
            }
        }

        impl<W:a and write it uncompressed
            /// to the   /// take in compressed data and write it uncompself.stream.total_out() as usize;

   {
        // While decoding flush is a noop
      tten(), output.unwritten_mut(), Action::Run)?;

  t<[u8]>>,
    ) -> Result<bool> {
        let prev Status, Stream};

pub struct Xz2Decoder {
    str_assert_send::<$name<Pin<Box<dyn AsyncWrite + Sendsk::Context<'_>,
                buf: &[u8],
                 /// Consumes this epin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner>       /// Creates a new encoder which will take iecoder, encoder::ZlibEncoder};
macro_rules! encode: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<staker().wake_by_ref();
            self.pended = tr    if self.pended {
            let next = Pin::n InterleavePending<T> {
    inner: T,
    pended: ssert_send::<$name<Pin<Box<dyn AsyncBufRead + Sendres_io::AsyncBufRead> futures_io::AsyncRead for $ndecoder state
            /// when reaching the enDecoder::new(read, crate::codec::$name::new()),
  macro_rules! decod
            this.amt += i as u64;
     Output> {
        let this = &mut *self;
     Unpin + ?Sized,
{
    CopyBuf {
        reader,
  ncWrite};

pub fn copy_buf<R, W>(reader: R, writerure = "tokio")]
impl<W: tokiot Context,
        bufs: &[std::io::IoSlice],
    (mut self: Pin<&mut Self>, cx: &mut Context, buf: uct TrackClosed<W> {
    inner: W,
    closed: boo)
        } else {
            Poll::Ready(Err(Erresult<()>> {
        if let State::Decoding = self

impl<W: AsyncWrite, D: Decode> AsyncWrite for Deut)? {
                        (State::Done, falsetput)? {
                        State::Finishing
, D> {
    pub fn new(writer: W, decoder: D) -> Seembers(true);

    let mut output = Vec::new();
  1][..]);
}

#[test]
#[ntest::timeout(1000)]
#[cfg(bers_with_padding() {
    let compressed = [
     unused)]
use futures::{executor::block_on, io::Asy/ The `amt` must be `<=` the number of bytes in thunction does not perform any I/O, it simply informcurrent task context (`cx`) to receive a notificat, &mut output)? {
            Poll::Pending if outbers {
                            this.decoder.re, output)?;
                        let len = inpupty() {
                        // Avoid attemptin>,
        output: &mut PartialBuffer<&mut [u8]>,
Decoding,
            multiple_members: false,
   y;
use futures_io::{AsyncBufRead, AsyncRead};
use u8]> + AsMut<[u8]>>)
        -> Result<bool>;

    are flushed and the end of the stream is written
ZstdDecoder, ZstdEncoder};

pub trait Encode {
   pub(crate) use self::brotli::{BrotliDecoder, Brotlate")]
mod deflate;
#[cfg(feature = "flate2")]
mods;
mod generic;

mod buf_write;
mod buf_writer;

u      )
            .field("written", &self.writte&mut [u8]>> {
        ready!(self.as_mut().partialResult<()>> {
        ready!(self.as_mut().flush_buld have returned with
                // `this.buf buf.len() >= this.buf.len() {
            if *th     &mut self.inner
    }

    /// Gets a pin/ Gets a reference to the underlying writer.
    pfered]))
            {
                Ok(0) => {
 *this.buffered {
            match ready!(this
  Err(e)) => {
                    ret = Err(e);
   (Ok(0)) => {
                    ret = Err(io::Errefault is currently 8 KB,
    /// but may change ioject;
use std::{
    cmp::min,
    fmt, io,
    pds to be redefined locally so that
// the `AsyncBu:timeout(1000)]
                    fn long_chunks::timeout(1000)]
                    fn short() {
 = write::decompress(input.as_ref(), 65_536);

                       one_to_six, InputStream,
           Box::pin(write::Encoder::with_quality(
     coder::with_quality(input, Level::Precise(0)))
    |input| Box::pin(write::Encoder::new(input)),
   sed = write::to_vec(
     pressed = write::compress(input.as_ref(), 20);
                let input = InputStream::new(vec![
  e::compress(one_to_six_stream().as_ref(), 2);
    mpress(one_to_six_stream().as_ref(), 65_536);
    t(1000)]
                    fn empty_chunk() {
  mpress {
                    use crate::utils::{
 utput, &[1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1][..]);m(compressed.chunks(1024));
    = (0..65_536).map(|_| rand::random()).collect();
:timeout(1000)]
                    fn long() {
       compressed.extend_from_slice(&[7, 8, 9, 10]);(1000)]
                    fn short_chunks() {
                   assert_eq!(output, &[0; 10][..]);       let result = read::poll_read(decoder, &mut meout(1000)]
                    fn to_full_output                      $impl::{bufread, read},
    test]
                    fn with_level_max() {
  #[test]
                    fn with_level_0() {
  t]
                    fn with_level_default() {
 ed = bufread::compress(bufread::from(&input));
   ndom()).collect(),
                        ]);

     let input = InputStream::new(vec![vec![]]);

                assert!(matches!(result, Ok(0)));
  _six, one_to_six_stream, InputStream, Level,
       ($impl:ident, $variant:ident) => {
        mod $  Self: Sized + Unpin,
    {
        limited::LimirackClosed, track_eof::TrackEof};
pub use async_co#![allow(dead_code, unused_macros)] // Different tas_mut().project().state = State::Finishing;
      if input.written().is_empty() => Poll::Pending,
               State::Done => (State::Done, true),
put)? {
                        (State::Done, fals else {
                        State::Decoding
  pl<W: AsyncWrite, D: Decode> DecodesyncWrite;
use pin_project_lite::pin_project;

#[dr::new(Vec::new());
    decoder.write_all(in_data)
    println!("{:?}", String::from_utf8(de_compres        std::mem::replace(self, Self::new(B::defauitten_from<C: AsRef<[u8]>>(&mut self, other: &mut Buffer<B> {
    pub(crate) fn new(buffer: B) -> Seruct PartialBuffer<B: AsRef<[u8]>> {
    buffer: B);
            self.decode(
                &mut Pdecode(input, output, FlushDecompress::None)? {
        Ok(status)
    }
}

impl Decode for FlateDec           self.decompress
                .decompub enum Xz2FileFormat {
    Xz,
    Lzma,
}

pub(cize) {
        *self.project().buffered += amt;
  l::Ready(Ok(&mut this.buf[*this.buffered..]))
    [*this.buffered..*this.buffered + len].copy_from_s// The only way that `partial_flush_buf` would haveftover data in the internal buffer is lost.
    p&W {
        &self.inner
    }

    /// Gets a mutthis.buffered, 0);
        *this.buffered -= *this     }
    }

    fn flush_buf(self: ten > 0 {
            this.buf.copy_within(*this.w               .as_mut()
                .poll_w self.project();

        let mut ret = Ok(());
   a new `BufWriter` with a default buffer capacity.nternals, and changed a bit to make it more effici_mut().do_poll_close(cx))?;
        ready!(self.prpty() {
            return Poll::Ready(Ok(0));
   roduced);

            if let State::Done = this.s     }
        }
    }

    fn do_poll_close(self:
        }
    }

    fn do_poll_flush(self:  | State::Done => panic!("Write after close"),
   ject();

        loop {
            let output = r, E> {
    pub fn new(writer: W, encoder: E) -> Sell_flush_buf`.
    fn produce(self:ush_buf` isn't
    /// called before calling it.
 when the object
    /// becomes readable or is clot to the inner reader if
    /// it is full.
    / mut out_buf = zstd_safe::OutBuffer::around(output_written);
        Ok(status.remaining == 0)
    }ecoder: Unshared::new(Decoder::new().unwrap()),
    ErrorKind::UnexpectedEof,
                "unexp> {
        // Because of the footer we have to haDecoding => {
                    let prior = outprocess(input, output, |this, input, output| {
             if input.unwritten().is_empty() || output    self.crc.update(&output.written()[prior..]);
 r: impl Fn(&mut Self, &mut PartialBuffer<I>, &mut         "amount of bytes read does not match",
   t bytes_read = crc.amount().to_le_bytes();

    if     Decode,
    },
    util::PartialBuffer,
};
us
    fn flush(
        &mut self,
        _output:r::new(crate::codec::Xz2FileFormat::Lzma, level),
Error::new(ErrorKind::Other, "out of memory")),
   => unreachable!(),

            // The Run actionest, but otherwise everything went normally.
     atus::FlushOk => Ok(false),

            // The Rus been met, meaning that no more data can be inputompression went ok.
            Status::RunOk => O     let prior_out = self.compress.total_out();

  to 250 inclusive. 0 is a special case,
    /// eqefault value of 30 gives reasonable behaviour overr than the standard algorithm by perhaps
    /// a for compression.
    ///
    /// The `work_factor            FlushCompress::Finish,
        )? {
  

        self.flushed = true;
        Ok(!output.sync blocks continuously and probably never comple>,
    ) -> Result<()> {
        self.flushed = faelf.compress.total_in() - prior_in) as usize);
   ate) fn new(level: Compression, zlib_header: bool)coder::new(),
        }
    }
}

impl Decode for Lnon-padding then it cannot start with null bytes,  while input.unwritten().first() == Some(&0) {
   on<u8>,
}

impl XzDecoder {
    pub fn new() -> Se>,
    ) -> Result<bool> {
        self.inner.fini inner: crate::codec::FlateEncoder,
}

impl Deflatll_buf(cx) {
            Poll::Ready(Ok(buf)) => {.filled().len() == len && buf.remaining() > 0 {
  f buf.is_empty() {
                    *eof = trueContext) -> Poll<Result<&[u8]>> {
        let (inneof);
        match inner.poll_read(cx, buf) {
   g_attr(not(feature = "all-implementations"), allow               use futures_io::AsyncBufRead;

    (self) -> $inner {
                self.inner.into          /// may otherwise confuse this encoder.
.
            pub fn get_ref(&self) -> &$inner          $($inherent_methods)*
            )*

   l
            /// read uncompressed data from an u        }

                State::Done => {}
     &mut *header);

                    if header.unwr       } else {
                        false
    ut *footer);

                    if footer.unwritFooter(_) | State::Done => panic!("encode after coelf.crc.update(&input.written()[prior_written..]);c::with_capacity(8);

        output.extend(&self.ression) -> Vec<u8> {
    let level_byte = if leve crate::codec::FlateEncoder,
    crc: Crc,
    stacx, &buf[..std::cmp::min(limit, buf.len())])
    } fn new(io: Io, limit: usize) -> Limited<Io> {
    + Send>>>>();
                _assert_sync::<$nam }

        impl<R: tokio::io::AsyncBufRead> tokios this decoder returning the underlying reader.
  o avoid tampering with the state of the reader whiressed member/frame and expect either EOF or anothber/frame decoding, if enabled this will reset theream and emit a stream of uncompressed data.
     d encoder;

pub(crate) use self::{decoder::XzDecod&[], output.unwritten_mut(), Action::Finish)?;

   => panic!("Unexpected lzma integrity check"),
   Kind::Other,
                "out of memory",
    revious_in = self.stream.total_in() as usize;
    ew_easy_encoder(level, Check::Crc64).unwrap(),
   esult;
use xz2::stream::{Action, Check, LzmaOptionen_from(input);

                    if data.unwri                      input.advance(len + 1);
         }

                State::Comment(data) => {
 Some(len) = memchr::memchr(0, input.unwritten()) ra(vec![0; usize::from(len)].into());
                let len = u16::from_le_bytes(data.ta   self.header = Header::parse(&data.take().into_i flag = input[3];

        let flags = Flags {
   Buffer<Vec<u8>>),
    Filename(Vec<u8>),
    Commeefault)]
pub(super) struct Header {
    flags: Flax: &mut Context<'_>,
        buf: &mut [u8],
    )       };

            if let State::Done = *this.         let mut input = PartialBuffer::new(input)
    pub fn into_inner(self) -> R {
        self.r[pin]
        reader: R,
        encoder: E,
     ::Ready(Ok(()))
    }

    fn poll_shutdown(mut seontext<'_>, buf: &[u8]) -> PocWrite for Encoder<W, E> {
    fn poll_write(self:            State::Encoding | State::Finishing => e::Encoding => this.encoder.flush(&mut output)?,

State::Done => panic!("Write after shutdown"),
   xt<'_>,
        input: &mut PartialBuffer<&[u8]>,
ate {
    Encoding,
    Finishing,
    Done,
}

pi"decompress", &"<no debug>")
            .finish()? {
            BrotliResult::ResultSuccess => Ok(self.decode(&mut PartialBuffer::new(&[][..]), outpself) -> Result<()> {
        self.state = Box::neadvance(input_len);
        output.advance(output_ -> Result<BrotliResult> {
        let in_buf = inBox::new(BrotliState::new(
                Standar// If set to 0, zstd selects a job size based on c feature guarded fn on next breaking release
       }

        /// Number of threads to spawn.
        /// Emit the size of the content (default: true /// This increases the default window size.
         /// Minimum size of matches searched for
     f the initial probe table in 4-byte entries (as a   /// type, to abstract over different versions ofspecific types for async-compression.
pub mod zstd     .try_into()
                    .unwrap_or(0)         .clamp(fastest.level(), best.level()),
  ature = "bzip2")]
    fn into_bzip2(self) -> bzip2ise(quality) => params.quality = quality.clamp(0, lity of compression, usually produces bigger size. "bzip2", feature = "flate2", feature = "xz2"))]
ur`"
)]
//!

#![cfg_attr(docsrs, feature(doc_auto_c   feature = "lzma",
    doc = "`lzma` | [`LzmaEncure = "gzip"),
    doc = "`gzip` (*inactive*) | `G=BrotliEncoder), [`BrotliDecoder`](?search=BrotliDsupport, there are currently a few
//! available c   doc = "[`futures-io`](crate::futures) | [`futurntation
//!
//! The first division is which underl:
//!

//!  Feature | Does
//! ---------|------
//nfilled());
        match self.do_poll_read(cx, &m&mut Context<'_>,
        buf: &mut ReadBuf<'_>,
       State::Next
                   this.reader.as_mut().consume(len);returned EOF.
                        *this.multipol) {
        self.multiple_members = enabled;
   et_mut(&mut self) -> &mut R {
        &mut self.re  decoder: D,
        state: State,
        multipesult {
        f.debug_struct("BrotliEncoder")
  tliEncoderOperation::BROTLI_OPERATION_FLUSH,
     _, _| (),
        ) <= 0
        {
           &mut in_buf.len(),
            in_buf,
    StandardAlloc::default());
        state.params = EncoderCreateInstance, BrotliEncoderHasMoreOutput, crate::codec::XzEncoder::new(level.into_xz2()),
 ?,
                    ),
                })
        /// Dictionaries provide better compression ratw_with_dict(level.into_zstd(), dictionary)?,
     n ratios for small files, but are required to
    and pre-trained
            /// dictionary, which eter::nb_workers()`]: crate::zstd::CParameter
    specified compression level and parameters, which
    algos!(@algo zstd ["zstd"] ZstdDecoder ZstdEncDecoder GzipEncoder <$inner>
        { @enc

     h_quality(inner: $inner, level: crate::Level) -> S{ @dec }
        );

        algos!(@algo bzip2 ["tli::enc::backward_references::BrotliEncoderParams     #[doc = concat!("A ", $algo_s, " encoder, or ($encoder_methods:tt)* }
        { @dec $($decoderufRead`](futures_io::AsyncBufRead) streams, both e           // There was insufficient memory in th          Status::FinishOk => unreachable!(),

        self.decompress = Decompress::new(false);
              .map_err(|e| std::io::Error::new(std::i "BzDecoder {{total_in: {}, total_out: {}}}",
    ;

use bzip2::{Decompress, Status};

pub struct Bz            use crate::util::{_assert_send, _asserncWrite> tokio::io::AsyncWrite for $name<o avoid losing resources when this is called.
     -> &mut W {
                self.inner.get_mut()
)
            }

            /// Acquires a mutabl W) -> $name<$inner> {
                $name {
   te::pin_project! {
            $(#[$attr])*
      .advance(self.stream.total_out() as usize - previo         "More memory needed",
            )),
   tatus::GetCheck => panic!("Unexpected lzma integri       stream: Stream::new_auto_decoder(u64::max_ve std::fmt::{Debug, Formatter, Result as FmtResultin;
                use tokio::io::AsyncWrite;

  &mut Self>,
                cx: &mut std::task::Cote of this encoder, so care should be taken
       avoid tampering with the state of the writer whic the underlying writer that this encoder is wrappi write it
                /// compressed to the gi  /// take in uncompressed data and write it comprl_shutdown(cx);
            if next.is_ready() {
      cx.waker().wake_by_ref();
   ded = false;
            }
            next
      fRead + Sync>>>>();
            }
        };
    }rt_sync};
                use core::pin::Pin;
    ote that this may discard internal state of this dpin::Pin<&mut Self>) -> std::pin::Pin<&mut R> {
         /// may otherwise confuse this decoder.
               $($($inherent_methods)*)*

     eam and
            /// emit a uncompressed streamecoder {
    ($(#[$attr:meta])* $name:ident<$inner>,
    ) -> Result<()> {
        self.inner.encodee std::io::Result;

use flate2::Compression;

#[deeady!(Pin::new(&mut this.writer).poll_flush(cx))?; W> Future for CopyBuf<'_, R, W>
where
    R: Asyn())) => {
                self.closed = true;
    cWrite + Unpin> tokio::io::AsyncWrite for TrackClout self.inner).poll_write_vectored(cx, bufs)
    }Result<usize>> {
        assert!(!self.closed);
   allow(unused))]
use std::{
    io::Result,
    pi      "Attempt to shutdown before finishing input"  _ => Poll::Ready(Ok(input.written().len())),
   
        match self.do_poll_write(cx, &mut input)?        };

            *this.state = state;

    new(output);

            let (state, done) = matc              State::Done => panic!("Write after e             if this.decoder.decode(input, &mut ouf>) -> Pin<&mut W> {
        self.project().writer(&self) -> &W {
        self.writer.get_ref()
    sult};

use crate::{
    codec::Decode,
    tokio:es-io")]
fn bufread_multiple_members_with_invalid_,
        vec![0, 0, 0, 0],
    ]
    .join(&[][..riter,
    generic::{Decoder, Encoder},
};

algos!/! Types which operate over [`AsyncWrite`](tokio::uffer that `amt` bytes have been written to its bull and cannot be flushed, the method returns `PollBufRead, D: Decode> AsyncRead for Decoder<R, D> {
ill_buf(cx))?;
                    if input.is_empone => State::Done,

                State::Next =        let done = this.decoder.decode(&mut input,tempting to reinitialise the decoder if the reader fn multiple_members(&mut self, enabled: bool) {
 _members: bool,
    }
}

impl<R: AsyncBufRead, D: 
    Done,
    Next,
}

pin_project! {
    #[deriva new member/frame of data.
    fn   /// Returns whether the internal buffers are flEncoder, Xz2FileFormat};
#[cfg(feature = "zlib")]
er, BzEncoder};
#[cfg(feature = "deflate")]
pub(crre = "brotli")]
mod brotli;
#[cfg(feature = "bzip2encoders and
//! decoders for various formats.

#[       &format_args!("{}/{}", self.buffered, self.amt;
    }
}

impl<W: fmt::Debug> fmt::Debug for BufWriter<W> {
    fn poll_partial_flush_buf(
     ffered != 0` is if it were Pending, so our waker w  ) -> Poll<io::Result<usize>> {
        let this  that any leftover data in the internal buffer is 
    /// It is inadvisable to directly write to th                Ok(n) => *this.written += n,
     this.written;
            *this.written = 0;

                       io::ErrorKind::WriteZero,
     ady(Ok(0)) => {
                    ret = Err(io::ange in the future.
    pub fn new(inner: W) -> SeFAULT_BUF_SIZE: usize = 8192;

pin_project! {
    ginally sourced from `futures_util::io::buf_writer                   assert_eq!(output, bytes);
         let compressed = sync::compress(&bytes);

   put = InputStream::from(compressed.chunks(2));
     let output = write::decom                  assert_eq!(output, &[][..]);
          algos::$variant::{sync, $impl::write},
                  Level::Precise(i32::max_value()),
                 one_to_six_stream().as_ref(),
              65_536,
                        );
                           |input| Box::pin(write::Enctest]
                    fn with_level_best() {
 :timeout(1000)]
                    fn long_chunk_ec![
                            (0..32_768).map(|)]
                    fn short_chunk_output() {
              assert_eq!(output, input.bytes());
  ssed = write::compress(input.as_ref(), 65_536);
      let mut decoder = bufread::Decoder::new(bufrea          sync::compress(&[6, 5, 4, 3, 2, 1]),
   {
                        let bytes: Vec<u8> = (0.> = (0..65_536).map(|_| rand::random()).collect();&input);
                        let output = bufr= bufread::decompress(bufread::from(&input));

   pressed = sync::compress(&[1, 2, 3, 4, 5, 6]);

      let compressed = sync::compress(&[0; 10]);

  et input = InputStream::new(vec![compressed]);
         },
                        one_to_six, one_t           bufread::from(&one_to_six_stream()),
     let encoder = bufread::Encoder::with_quality(
          let compressed = read::to_vec(encoder);
     let output = sync::decompress(&compressed);

               assert_eq!(output, one_to_six());
    let compressed = bufread::compress(bufread::fromimeout(1000)]
                    fn empty_chunk()     #[test]
                    #[ntest::timeout(er, encoder::FlateEncoder};
macro_rules! io_test_c interleave_pending::InterleavePending<Self>
    w;

pub fn one_to_six_stream() -> InputStream {
   d input_stream;
#[cfg(feature = "tokio")]
mod tokif let State::Done = self.as_mut().project().state Poll::Pending if input.written().is_empty() => Pol                    (State::Finishing, false)
    
                    (State::Decoding, done)
     after end of stream"),
    tput)? {
                        State::Done
         self.writer.into_inner()
    }

    fn do_poller<W, D> {
    pub fn new(writer: W, decoder: D) -Debug)]
    pub struct Decoder<W, D: Decode> {
   ?;
    Ok(encoder.into_inner())
}

async fn decompmpress(&compressed_data).await?;
    assert_eq!(delen]);

        self.advance(len);
        other.a-> B {
        self.buffer
    }
}

impl<B: AsRef<> &[u8] {
        &self.buffer.as_ref()[self.indexssert_sync<T: Sync>() {}

#[derive(Debug, Default)press::None,
            )?;
            if output> Ok(true),
            Status::BufError => Err(Er     self.decompress.reset(self.zlib_header);
          decompress: Decompress::new(zlib_header),
  d, Result};

use flate2::{Decompress, FlushDecomprer")
            .field("writer", &self.inner)
   <W: AsyncWrite> AsyncBufWrite for BufWriter<W> {
 Ok(len))
        }
    }

    fn poll_flush(mut seuffered + buf.len() > this.buf.len() {
  er
    }

    /// Consumes this `BufWriter`, returet_pin_mut(self: Pin<&mut Self>) -> Pin<&mut W> {
         "failed to write the buffered data",
    this
                .inner
                .as_mu:Ready(ret)
        } else if *this.buffered == 0 e(cx, &this.buf[*this.written..*this.buffered])
  ;
        while *this.written < *this.buffered {
 <[u8]>,
        written: usize,
        buffered: core::ready;
use pin_project_lite::pin_project;
usll::Ready(Ok(()))
    }

    fn poll_close(mut selalBuffer::new(buf);

        match self.do_poll_wr {
                    if this.encoder.finish(&mut    };

            let produced = outp) -> Poll<Result<()>> {
        let mut this = sel      this.writer.as_mut().produce(produced);

       let mut output = PartialBuffer::new(output);

ter: BufWriter::new(writer),
            encoder,
res::write::{AsyncBufWrite, BufWriter},
    util:: some amount of its buffer, returned from `poll_fl  ) -> Poll<io::Result<&mut [u8]>>;

    /// Tellsternal buffer to write to, flushing data out to thbytes_left = self.decoder.get_mut().flush(&mut out        output.advance(status.bytes_written);
    lf.decoder.get_mut().reinit()?;
        Ok(())
   truct ZstdDecoder {
    decoder: Unshared<Decoder<e to have already flushed all the data out before        this.inner.decode(input, output)
        }).inner.reinit()?;
        self.crc = Crc::new();
     check_footer(&self.crc, footer.written())?;
         let done = inner(self, input, output)?;
         if let Some(header) = parser.input(input)? {tate: State::Header(header::Parser::default()),
  id gzip footer length",
        ));
    }

    letEncoder};
#[macro_use]
mod utils;

test_cases!(bro on LZMA 1 is not supported
        Ok(true)
    }d::io::Result;

#[derive(Debug)]
pub struct LzmaEn    // the request, but otherwise everything went     // Decompression went fine, nothing much to re// The stream's end has been met, meaning that no / The Flush action on a compression went ok.
     y in the input or output buffer to complete
      to report.
            Status::Ok => Ok(()),

    () - prior_out) as usize);

        Ok(status)
   esult<Status> {
        let prior_in = self.compree fallback. You should set
    /// this parameter o matter how bad the
    /// input.
    ///
    //, f: &mut fmt::Formatter<'_>) -> fmt::Result {
   new(ErrorKind::Other, "unexpected BufError")),
   ().len() == old_len {
                break;
                 FlushCompress::Sync,
        )?;

    h self.encode(input, output, FlushCompress::None)?ess
            .compress(input.unwritten(), outpu{
    compress: Compress,
    flushed: bool,
}

imec::Encode, util::PartialBuffer};
use std::io::{Ere for LzmaDecoder {
    fn reinit(&mut self) -> Reool> {
        if self.skip_padding.is_some() {
  
                    ErrorKind::InvalidData,
     *count -= 1;
                if *count == 0 {
    codec::Xz2Decoder,
    skip_padding: Option<u8>,
}sult<bool> {
        self.inner.flush(output)
    t().0.consume(amt)
    }
}
use crate::{codec::Enco      other => other,
        }
    }

    fn const!(!*eof);
        let len = buf.filled().len();
 fn consume(self: Pin<&mut Self>, amt: usize) {
   -io")]
impl<R: futures::io::AsyncBufRead + Unpin> inner, eof) = self.project();
        assert!(!*eol},
};

pub struct TrackEof<R> {
    inner: R,
          const _: () = {
            fn _assert() {
 internal state of this encoder, so care should be    /// Acquires a pinned mutable refereder that this encoder is
            /// wrapping.   inner: crate::futures::bufread::Encoder<$inner,`](futures_io::AsyncRead) interface and will
                        self.state = State::Done;
         output.copy_unwritten_from(&mut *header);

       if done {
                return Ok(true);
   ut)?,

                State::Footer(footer) => {
;
            }
        }
    }

    fn flush(
   tate::Encoding => {
                    let prior_sult<()> {
        loop {
            match &mut sGzipEncoder {
    pub(crate) fn new(level: Compres.poll_shutdown(cx)
    }
}
mod decoder;
mod encode      Pin::new(&mut self.io).poll_write(cx, &buf[.or Limited<W> {
    fn poll_write(
        mut sel          _assert_send::<$name<Pin<Box<dyn AsyncBu    /// to avoid losing resources when this is cal   ///
            /// Note that care must be taker which
            /// may otherwise confuse this          }

            /// Acquires a reference   /// Creates a new decoder which will read compre   /// This structure implements an [`AsyncRead`]($inner:ident> $({ $($inherent_methods:tt)* })*) =>      let status = self
            .stream
      e),
            Status::StreamEnd => Ok(true),
            Status::MemNeeded => Err(std::io::Error::et previous_out = self.stream.total_out() as usize}
}

impl Encode for Xz2Encoder {
    fn encode(
 ncoder {
    fn fmt(&self, f: &mut Formatter<'_>) urn Ok(Some(std::mem::take(&mut self.header)));
       data.extend_from_slice(input.unwritten());
                if !self.header.flags.comment {
    extend_from_slice(&input.unwritten()[..len]);
    se {
                        return Ok(None);
                   data.copy_unwritten_from(input);

  self.state = State::ExtraLen(<_>::default());
              ascii: (flag & 0b0000_0001) != 0,
     Buffer<[u8; 2]>),
    Done,
}

impl Default for St       _ => Poll::Ready(Ok(output.written().len())ll<Result<usize>> {
        if buf.is_empty() {
  e::Done,
            };

            if let State:op {
            *this.state = match this.state {
(&self) -> &R {
        &self.reader
    }

    puEncoder<R, E> {
    pub fn new(reader: R, encoder::Encode, util::PartialBuffer};
use futures_core::rult<()>> {
        ready!(self.as_mut().do_poll_fl}

impl<W: AsyncWrite, E: Encode> AsyncWrite for Eoject();

        loop {
            let output = tate::Finishing | State::Done => panic!("Flush aft Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Resdy!(this.writer.as_mut().poll_partial_flush_buf(cxfn get_ref(&self) -> &W {
        self.writer.get_
        #[pin]
        writer: BufWriter<W>,
       task::{Context, Poll},
};
use std::io::Result;
BrotliResult::ResultFailure => unreachable!(),
    | BrotliResult::NeedsMoreInput => Ok(false),
    t<bool> {
        match self.decode(input, output)   &mut self.state,
        ) {
            Brotliuf = input.unwritten();
        let mut out_buf = tandardAlloc, BrotliDecompressStream, BrotliResult}

        pub(crate) fn as_zstd(&self) -> libzstd otherwise it will cause a panic
        /// when ).
        pub fn checksum_flag(value: bool) -> Se  /// Size of each bucket in the LDM hash table fohe long-distance matching table (as a power of two   Self(MinMatch(value))
        }

        /// St of two)
        pub fn hash_log(value: u32) -> Se)]
    pub struct CParameter(libzstd::stream::raw:  }
}

#[cfg(feature = "zstd")]
/// This module co Self::Best => best,
            Self::Precise(qualf::Default => bzip2::Compression::default(),
        let fastest = bzip2::Compression::fast();
    match self {
            Self::Fastest => params.qebug)]
pub enum Level {
    /// Fastest quality ofnto;

#[macro_use]
mod macros;
mod codec;

#[cfg(f"`zlib` (*inactive*) | `ZlibEncoder`, `ZlibDecoderXzEncoder), [`XzDecoder`](?search=XzDecoder)"
)]
#er`, `DeflateDecoder`"
)]
#![cfg_attr(
    featurep2",
    doc = "`bzip2` | [`BzEncoder`](?search=Bztokio` (*inactive*) | `tokio::io::AsyncBufRead`, `)"
)]
#![cfg_attr(
    not(feature = "futures-io")tations, needs to be paired with a selection of al`   | Activates all implementations and algorithmsoll<Result<()>> {
        if buf.remaining() == 0 {
                return Poll::Ready(Ok(()));
    poll_fill_buf(cx))?;
                    if input.            if this.decoder.finish(output)? {
       State::Flushing
                    } else {
     let input = ready!(this.reader.as_mut().poll_fidecoder,
            state: State::Decoding,
     

#[derive(Debug)]
enum State {
    Decoding,
    inish()
    }
}
use core::{
    pin::Pin,
    taskialBuffer::new(&[][..]),
            output,
            return Err(Error::new(ErrorKind::Other, "br let mut input_len = 0;
        let mut output_len &mut self,
        input: &mut PartialBuffer<implstd::{
    fmt,
    io::{Error, ErrorKind, Result}algos!(@algo lzma ["lzma"] LzmaDecoder LzmaEncoder       );

        algos!(@algo xz ["xz"] XzDecodestd::io::Result<Self> {
                Ok(Self {
codec::ZstdEncoder::new_with_dict(level.into_zstd( dictionary: &[u8]) -> ::std::io::Result<Self> {
    /// Creates a new encoder, using the specified  if this function is called with a [`CParameter::n uncompressed data from the given stream and emit    pub fn with_quality(inner: $inner, level: crate(level.into_flate2()),
                    ),
    lateDecoder DeflateEncoder <$inner>
        { @encner: crate::$($mod::)+generic::Encoder::new(
           crate::codec::BrotliEncoder::new(level.into_   Self::with_quality(inner, crate::Level::Default      #[cfg(feature = $algo_s)]
        decoder! {nwritten().is_empty())
    }

    fn finish(
     p {
            let old_len = output.written().len     // The Finish action on compression went ok.
)
    }
}

impl Decode for BzDecoder {
    fn rein     input.advance((self.decompress.total_in() - p  }
    }

    fn decode(
        &mut self,
     ;

pub(crate) use self::{decoder::GzipDecoder, enc         self.project().inner.poll_flush(cx)
         self.project().inner.poll_write(cx, buf)
     d.
            pub fn into_inner(self) -> W {
    be taken to avoid tampering with the state of the erence to the underlying reader that this decoder   inner: crate::tokio::write::Decoder::new(read, c) => {
        pin_project_lite::pin_project! {
         .process(&[], output.unwritten_mut(), Actiof<[u8]> + AsMut<[u8]>>,
    ) -> Result<bool> {
  ut);

        match status {
            Status::Oer<impl AsRef<[u8]>>,
        output: &mut Partial::{codec::Decode, util::PartialBuffer};

use std::rt() {
                use crate::util::{_assert_sask::Context<'_>,
                buf: &[u8],
    his encoder returning the underlying writer.
              self.project().inner.get_pin_mut()
         pub fn get_mut(&mut self) -> &mut $inner {
            impl<$inner: tokio::io::AsyncWrite> $name< compressed to an underlying stream.
            #       Poll::Pending
        }
    }
}
#[macro_uset<()>> {
        if self.pended {
            let mut self: Pin<&mut Self>,
        cx: &mut Context) -> Self {
        Self {
            inner,
           ) -> std::task::Poll<std::io::Result<usize>
            fn poll_read(
                self: s   pub fn get_pin_mut(self: std::pin::Pin<&mut Selapping.
            ///
            /// Note that       self.inner.multiple_members(enabled);
      :codec::$name>,
            }
        }

        iug)]
            pub struct $name<$inner> {