@@ -3,8 +3,8 @@ use crate::structs::query_colored_counters::{ColorsRange, QueryColoredCountersSe
33use colors:: colors_manager:: ColorMapReader ;
44use colors:: colors_manager:: { ColorsManager , ColorsMergeManager } ;
55use config:: {
6- ColorIndexType , KEEP_FILES , QUERIES_COUNT_MIN_BATCH , SwapPriority , get_compression_level_info ,
7- get_memory_mode,
6+ ColorIndexType , KEEP_FILES , OUTPUT_COMPRESSION_LEVEL , QUERIES_COUNT_MIN_BATCH , SwapPriority ,
7+ get_compression_level_info , get_memory_mode,
88} ;
99use flate2:: Compression ;
1010use ggcat_logging:: UnrecoverableErrorLogging ;
@@ -32,6 +32,7 @@ enum QueryOutputFileWriter {
3232 Plain ( File ) ,
3333 LZ4Compressed ( lz4:: Encoder < File > ) ,
3434 GzipCompressed ( flate2:: write:: GzEncoder < File > ) ,
35+ ZstdCompressed ( zstd:: stream:: write:: Encoder < ' static , File > ) ,
3536}
3637
3738impl Write for QueryOutputFileWriter {
@@ -40,6 +41,7 @@ impl Write for QueryOutputFileWriter {
4041 QueryOutputFileWriter :: Plain ( w) => w. write ( buf) ,
4142 QueryOutputFileWriter :: LZ4Compressed ( w) => w. write ( buf) ,
4243 QueryOutputFileWriter :: GzipCompressed ( w) => w. write ( buf) ,
44+ QueryOutputFileWriter :: ZstdCompressed ( w) => w. write ( buf) ,
4345 }
4446 }
4547
@@ -48,6 +50,7 @@ impl Write for QueryOutputFileWriter {
4850 QueryOutputFileWriter :: Plain ( w) => w. flush ( ) ,
4951 QueryOutputFileWriter :: LZ4Compressed ( w) => w. flush ( ) ,
5052 QueryOutputFileWriter :: GzipCompressed ( w) => w. flush ( ) ,
53+ QueryOutputFileWriter :: ZstdCompressed ( w) => w. flush ( ) ,
5154 }
5255 }
5356}
@@ -85,17 +88,29 @@ pub fn colored_query_output<MH: HashFunctionFactory, CX: ColorsManager>(
8588 let query_output_file = File :: create ( & output_file)
8689 . log_unrecoverable_error_with_data ( "Cannot create output file" , output_file. display ( ) ) ?;
8790
91+ let output_compression_level = OUTPUT_COMPRESSION_LEVEL . load ( Ordering :: Relaxed ) ;
92+
8893 let query_output = Mutex :: new ( (
8994 BufWriter :: new (
9095 match output_file. extension ( ) . map ( |e| e. to_str ( ) ) . flatten ( ) {
9196 Some ( "lz4" ) => QueryOutputFileWriter :: LZ4Compressed (
9297 lz4:: EncoderBuilder :: new ( )
93- . level ( 4 )
98+ . level ( output_compression_level . min ( 16 ) )
9499 . build ( query_output_file)
95100 . unwrap ( ) ,
96101 ) ,
97- Some ( "gz" ) => QueryOutputFileWriter :: GzipCompressed (
98- flate2:: GzBuilder :: new ( ) . write ( query_output_file, Compression :: default ( ) ) ,
102+ Some ( "gz" ) => {
103+ QueryOutputFileWriter :: GzipCompressed ( flate2:: GzBuilder :: new ( ) . write (
104+ query_output_file,
105+ Compression :: new ( output_compression_level. min ( 9 ) ) ,
106+ ) )
107+ }
108+ Some ( "zst" ) | Some ( "zstd" ) => QueryOutputFileWriter :: ZstdCompressed (
109+ zstd:: stream:: write:: Encoder :: new (
110+ query_output_file,
111+ output_compression_level. min ( 22 ) as i32 ,
112+ )
113+ . unwrap ( ) ,
99114 ) ,
100115 _ => QueryOutputFileWriter :: Plain ( query_output_file) ,
101116 } ,
0 commit comments