1
1
use anyhow:: { Context , Error } ;
2
2
use flate2:: { read:: GzDecoder , write:: GzEncoder } ;
3
3
use rayon:: prelude:: * ;
4
- use std:: { convert :: TryFrom , fmt, io:: Read , io:: Write , path:: Path , str:: FromStr } ;
4
+ use std:: { fmt, io:: Read , io:: Write , path:: Path , str:: FromStr } ;
5
5
use xz2:: { read:: XzDecoder , write:: XzEncoder } ;
6
6
7
7
#[ derive( Default , Debug , Copy , Clone ) ]
8
8
pub enum CompressionProfile {
9
+ NoOp ,
9
10
Fast ,
10
11
#[ default]
11
12
Balanced ,
@@ -20,6 +21,7 @@ impl FromStr for CompressionProfile {
20
21
"fast" => Self :: Fast ,
21
22
"balanced" => Self :: Balanced ,
22
23
"best" => Self :: Best ,
24
+ "no-op" => Self :: NoOp ,
23
25
other => anyhow:: bail!( "invalid compression profile: {other}" ) ,
24
26
} )
25
27
}
@@ -31,6 +33,7 @@ impl fmt::Display for CompressionProfile {
31
33
CompressionProfile :: Fast => f. write_str ( "fast" ) ,
32
34
CompressionProfile :: Balanced => f. write_str ( "balanced" ) ,
33
35
CompressionProfile :: Best => f. write_str ( "best" ) ,
36
+ CompressionProfile :: NoOp => f. write_str ( "no-op" ) ,
34
37
}
35
38
}
36
39
}
@@ -78,10 +81,16 @@ impl CompressionFormat {
78
81
CompressionProfile :: Fast => flate2:: Compression :: fast ( ) ,
79
82
CompressionProfile :: Balanced => flate2:: Compression :: new ( 6 ) ,
80
83
CompressionProfile :: Best => flate2:: Compression :: best ( ) ,
84
+ CompressionProfile :: NoOp => panic ! (
85
+ "compression profile 'no-op' should not call `CompressionFormat::encode`."
86
+ ) ,
81
87
} ,
82
88
) ) ,
83
89
CompressionFormat :: Xz => {
84
90
let encoder = match profile {
91
+ CompressionProfile :: NoOp => panic ! (
92
+ "compression profile 'no-op' should not call `CompressionFormat::encode`."
93
+ ) ,
85
94
CompressionProfile :: Fast => {
86
95
xz2:: stream:: MtStreamBuilder :: new ( ) . threads ( 6 ) . preset ( 1 ) . encoder ( ) . unwrap ( )
87
96
}
0 commit comments