@@ -154,28 +154,35 @@ mod unshared;
154
154
mod util;
155
155
156
156
#[ cfg( feature = "brotli" ) ]
157
- use brotli:: enc:: backward_references:: BrotliEncoderParams ;
157
+ pub mod brotli;
158
+ #[ cfg( feature = "zstd" ) ]
159
+ pub mod zstd;
158
160
159
161
/// Level of compression data should be compressed with.
160
162
#[ non_exhaustive]
161
163
#[ derive( Clone , Copy , Debug ) ]
162
164
pub enum Level {
163
165
/// Fastest quality of compression, usually produces bigger size.
164
166
Fastest ,
167
+
165
168
/// Best quality of compression, usually produces the smallest size.
166
169
Best ,
170
+
167
171
/// Default quality of compression defined by the selected compression algorithm.
168
172
Default ,
169
- /// Precise quality based on the underlying compression algorithms'
170
- /// qualities. The interpretation of this depends on the algorithm chosen
171
- /// and the specific implementation backing it.
172
- /// Qualities are implicitly clamped to the algorithm's maximum.
173
+
174
+ /// Precise quality based on the underlying compression algorithms' qualities. The
175
+ /// interpretation of this depends on the algorithm chosen and the specific implementation
176
+ /// backing it. Qualities are implicitly clamped to the algorithm's maximum.
173
177
Precise ( i32 ) ,
174
178
}
175
179
176
180
impl Level {
177
181
#[ cfg( feature = "brotli" ) ]
178
- fn into_brotli ( self , mut params : BrotliEncoderParams ) -> BrotliEncoderParams {
182
+ fn into_brotli (
183
+ self ,
184
+ mut params : :: brotli:: enc:: backward_references:: BrotliEncoderParams ,
185
+ ) -> :: brotli:: enc:: backward_references:: BrotliEncoderParams {
179
186
match self {
180
187
Self :: Fastest => params. quality = 0 ,
181
188
Self :: Best => params. quality = 11 ,
@@ -243,118 +250,3 @@ impl Level {
243
250
}
244
251
}
245
252
}
246
-
247
- #[ cfg( feature = "zstd" ) ]
248
- /// This module contains zstd-specific types for async-compression.
249
- pub mod zstd {
250
- use libzstd:: stream:: raw:: CParameter :: * ;
251
-
252
- /// A compression parameter for zstd. This is a stable wrapper around zstd's own `CParameter`
253
- /// type, to abstract over different versions of the zstd library.
254
- ///
255
- /// See the [zstd documentation](https://facebook.github.io/zstd/zstd_manual.html) for more
256
- /// information on these parameters.
257
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
258
- pub struct CParameter ( libzstd:: stream:: raw:: CParameter ) ;
259
-
260
- impl CParameter {
261
- /// Window size in bytes (as a power of two)
262
- pub fn window_log ( value : u32 ) -> Self {
263
- Self ( WindowLog ( value) )
264
- }
265
-
266
- /// Size of the initial probe table in 4-byte entries (as a power of two)
267
- pub fn hash_log ( value : u32 ) -> Self {
268
- Self ( HashLog ( value) )
269
- }
270
-
271
- /// Size of the multi-probe table in 4-byte entries (as a power of two)
272
- pub fn chain_log ( value : u32 ) -> Self {
273
- Self ( ChainLog ( value) )
274
- }
275
-
276
- /// Number of search attempts (as a power of two)
277
- pub fn search_log ( value : u32 ) -> Self {
278
- Self ( SearchLog ( value) )
279
- }
280
-
281
- /// Minimum size of matches searched for
282
- pub fn min_match ( value : u32 ) -> Self {
283
- Self ( MinMatch ( value) )
284
- }
285
-
286
- /// Strategy-dependent length modifier
287
- pub fn target_length ( value : u32 ) -> Self {
288
- Self ( TargetLength ( value) )
289
- }
290
-
291
- /// Enable long-distance matching mode to look for and emit long-distance references.
292
- ///
293
- /// This increases the default window size.
294
- pub fn enable_long_distance_matching ( value : bool ) -> Self {
295
- Self ( EnableLongDistanceMatching ( value) )
296
- }
297
-
298
- /// Size of the long-distance matching table (as a power of two)
299
- pub fn ldm_hash_log ( value : u32 ) -> Self {
300
- Self ( LdmHashLog ( value) )
301
- }
302
-
303
- /// Minimum size of long-distance matches searched for
304
- pub fn ldm_min_match ( value : u32 ) -> Self {
305
- Self ( LdmMinMatch ( value) )
306
- }
307
-
308
- /// Size of each bucket in the LDM hash table for collision resolution (as a power of two)
309
- pub fn ldm_bucket_size_log ( value : u32 ) -> Self {
310
- Self ( LdmBucketSizeLog ( value) )
311
- }
312
-
313
- /// Frequency of using the LDM hash table (as a power of two)
314
- pub fn ldm_hash_rate_log ( value : u32 ) -> Self {
315
- Self ( LdmHashRateLog ( value) )
316
- }
317
-
318
- /// Emit the size of the content (default: true).
319
- pub fn content_size_flag ( value : bool ) -> Self {
320
- Self ( ContentSizeFlag ( value) )
321
- }
322
-
323
- /// Emit a checksum (default: false).
324
- pub fn checksum_flag ( value : bool ) -> Self {
325
- Self ( ChecksumFlag ( value) )
326
- }
327
-
328
- /// Emit a dictionary ID when using a custom dictionary (default: true).
329
- pub fn dict_id_flag ( value : bool ) -> Self {
330
- Self ( DictIdFlag ( value) )
331
- }
332
-
333
- /// Number of threads to spawn.
334
- ///
335
- /// If set to 0, compression functions will block; if set to 1 or more, compression will
336
- /// run in background threads and `flush` pushes bytes through the compressor.
337
- ///
338
- /// # Panics
339
- ///
340
- /// This parameter requires feature `zstdmt` to be enabled, otherwise it will cause a panic
341
- /// when used in `ZstdEncoder::with_quality_and_params()` calls.
342
- //
343
- // TODO: make this a normal feature guarded fn on next breaking release
344
- #[ cfg_attr( docsrs, doc( cfg( feature = "zstdmt" ) ) ) ]
345
- pub fn nb_workers ( value : u32 ) -> Self {
346
- Self ( NbWorkers ( value) )
347
- }
348
-
349
- /// Number of bytes given to each worker.
350
- ///
351
- /// If set to 0, zstd selects a job size based on compression parameters.
352
- pub fn job_size ( value : u32 ) -> Self {
353
- Self ( JobSize ( value) )
354
- }
355
-
356
- pub ( crate ) fn as_zstd ( & self ) -> libzstd:: stream:: raw:: CParameter {
357
- self . 0
358
- }
359
- }
360
- }
0 commit comments