11use anyhow:: { Context , Error } ;
22use flate2:: { read:: GzDecoder , write:: GzEncoder } ;
33use 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 } ;
55use xz2:: { read:: XzDecoder , write:: XzEncoder } ;
66
77#[ derive( Default , Debug , Copy , Clone ) ]
88pub enum CompressionProfile {
9+ NoOp ,
910 Fast ,
1011 #[ default]
1112 Balanced ,
@@ -20,6 +21,7 @@ impl FromStr for CompressionProfile {
2021 "fast" => Self :: Fast ,
2122 "balanced" => Self :: Balanced ,
2223 "best" => Self :: Best ,
24+ "no-op" => Self :: NoOp ,
2325 other => anyhow:: bail!( "invalid compression profile: {other}" ) ,
2426 } )
2527 }
@@ -31,6 +33,7 @@ impl fmt::Display for CompressionProfile {
3133 CompressionProfile :: Fast => f. write_str ( "fast" ) ,
3234 CompressionProfile :: Balanced => f. write_str ( "balanced" ) ,
3335 CompressionProfile :: Best => f. write_str ( "best" ) ,
36+ CompressionProfile :: NoOp => f. write_str ( "no-op" ) ,
3437 }
3538 }
3639}
@@ -78,10 +81,16 @@ impl CompressionFormat {
7881 CompressionProfile :: Fast => flate2:: Compression :: fast ( ) ,
7982 CompressionProfile :: Balanced => flate2:: Compression :: new ( 6 ) ,
8083 CompressionProfile :: Best => flate2:: Compression :: best ( ) ,
84+ CompressionProfile :: NoOp => panic ! (
85+ "compression profile 'no-op' should not call `CompressionFormat::encode`."
86+ ) ,
8187 } ,
8288 ) ) ,
8389 CompressionFormat :: Xz => {
8490 let encoder = match profile {
91+ CompressionProfile :: NoOp => panic ! (
92+ "compression profile 'no-op' should not call `CompressionFormat::encode`."
93+ ) ,
8594 CompressionProfile :: Fast => {
8695 xz2:: stream:: MtStreamBuilder :: new ( ) . threads ( 6 ) . preset ( 1 ) . encoder ( ) . unwrap ( )
8796 }
0 commit comments