@@ -38,6 +38,15 @@ pub enum CompressionMethod {
38
38
/// Compress the file using LZMA
39
39
#[ cfg( feature = "lzma" ) ]
40
40
Lzma ,
41
+ #[ cfg( feature = "legacy-zip" ) ]
42
+ /// Method 1 Shrink
43
+ Shrink ,
44
+ #[ cfg( feature = "legacy-zip" ) ]
45
+ /// Reduce (Method 2-5)
46
+ Reduce ( u8 ) ,
47
+ #[ cfg( feature = "legacy-zip" ) ]
48
+ /// Method 6 Implode/explode
49
+ Implode ,
41
50
/// Compress the file using XZ
42
51
#[ cfg( feature = "xz" ) ]
43
52
Xz ,
@@ -55,11 +64,40 @@ pub enum CompressionMethod {
55
64
/// All compression methods defined for the ZIP format
56
65
impl CompressionMethod {
57
66
pub const STORE : Self = CompressionMethod :: Stored ;
67
+ #[ cfg( feature = "legacy-zip" ) ]
68
+ pub const SHRINK : Self = CompressionMethod :: Shrink ;
69
+ #[ cfg( not( feature = "legacy-zip" ) ) ]
70
+ /// Legacy compression method (enable feature `legacy-zip` to get support)
58
71
pub const SHRINK : Self = CompressionMethod :: Unsupported ( 1 ) ;
72
+ #[ cfg( feature = "legacy-zip" ) ]
73
+ /// Legacy compression method
74
+ pub const REDUCE_1 : Self = CompressionMethod :: Reduce ( 1 ) ;
75
+ #[ cfg( not( feature = "legacy-zip" ) ) ]
76
+ /// Legacy compression method (enable feature `legacy-zip` to get support)
59
77
pub const REDUCE_1 : Self = CompressionMethod :: Unsupported ( 2 ) ;
78
+ #[ cfg( feature = "legacy-zip" ) ]
79
+ /// Legacy compression method
80
+ pub const REDUCE_2 : Self = CompressionMethod :: Reduce ( 2 ) ;
81
+ #[ cfg( not( feature = "legacy-zip" ) ) ]
82
+ /// Legacy compression method (enable feature `legacy-zip` to get support)
60
83
pub const REDUCE_2 : Self = CompressionMethod :: Unsupported ( 3 ) ;
84
+ #[ cfg( feature = "legacy-zip" ) ]
85
+ /// Legacy compression method
86
+ pub const REDUCE_3 : Self = CompressionMethod :: Reduce ( 3 ) ;
87
+ #[ cfg( not( feature = "legacy-zip" ) ) ]
88
+ /// Legacy compression method (enable feature `legacy-zip` to get support)
61
89
pub const REDUCE_3 : Self = CompressionMethod :: Unsupported ( 4 ) ;
90
+ #[ cfg( feature = "legacy-zip" ) ]
91
+ /// Legacy compression method
92
+ pub const REDUCE_4 : Self = CompressionMethod :: Reduce ( 4 ) ;
93
+ #[ cfg( not( feature = "legacy-zip" ) ) ]
94
+ /// Legacy compression method (enable feature `legacy-zip` to get support)
62
95
pub const REDUCE_4 : Self = CompressionMethod :: Unsupported ( 5 ) ;
96
+ #[ cfg( feature = "legacy-zip" ) ]
97
+ /// Legacy compression method
98
+ pub const IMPLODE : Self = CompressionMethod :: Implode ;
99
+ #[ cfg( not( feature = "legacy-zip" ) ) ]
100
+ /// Legacy compression method (enable feature `legacy-zip` to get support)
63
101
pub const IMPLODE : Self = CompressionMethod :: Unsupported ( 6 ) ;
64
102
#[ cfg( feature = "_deflate-any" ) ]
65
103
pub const DEFLATE : Self = CompressionMethod :: Deflated ;
@@ -105,6 +143,18 @@ impl CompressionMethod {
105
143
pub ( crate ) const fn parse_from_u16 ( val : u16 ) -> Self {
106
144
match val {
107
145
0 => CompressionMethod :: Stored ,
146
+ #[ cfg( feature = "legacy-zip" ) ]
147
+ 1 => CompressionMethod :: Shrink ,
148
+ #[ cfg( feature = "legacy-zip" ) ]
149
+ 2 => CompressionMethod :: Reduce ( 1 ) ,
150
+ #[ cfg( feature = "legacy-zip" ) ]
151
+ 3 => CompressionMethod :: Reduce ( 2 ) ,
152
+ #[ cfg( feature = "legacy-zip" ) ]
153
+ 4 => CompressionMethod :: Reduce ( 3 ) ,
154
+ #[ cfg( feature = "legacy-zip" ) ]
155
+ 5 => CompressionMethod :: Reduce ( 4 ) ,
156
+ #[ cfg( feature = "legacy-zip" ) ]
157
+ 6 => CompressionMethod :: Implode ,
108
158
#[ cfg( feature = "_deflate-any" ) ]
109
159
8 => CompressionMethod :: Deflated ,
110
160
#[ cfg( feature = "deflate64" ) ]
@@ -138,6 +188,13 @@ impl CompressionMethod {
138
188
pub ( crate ) const fn serialize_to_u16 ( self ) -> u16 {
139
189
match self {
140
190
CompressionMethod :: Stored => 0 ,
191
+ #[ cfg( feature = "legacy-zip" ) ]
192
+ CompressionMethod :: Shrink => 1 ,
193
+ #[ cfg( feature = "legacy-zip" ) ]
194
+ CompressionMethod :: Reduce ( n) => 1 + n as u16 ,
195
+ #[ cfg( feature = "legacy-zip" ) ]
196
+ CompressionMethod :: Implode => 6 ,
197
+
141
198
#[ cfg( feature = "_deflate-any" ) ]
142
199
CompressionMethod :: Deflated => 8 ,
143
200
#[ cfg( feature = "deflate64" ) ]
@@ -215,6 +272,12 @@ pub(crate) enum Decompressor<R: io::BufRead> {
215
272
Zstd ( zstd:: Decoder < ' static , R > ) ,
216
273
#[ cfg( feature = "lzma" ) ]
217
274
Lzma ( Lzma < R > ) ,
275
+ #[ cfg( feature = "legacy-zip" ) ]
276
+ Shrink ( crate :: legacy:: shrink:: ShrinkDecoder < R > ) ,
277
+ #[ cfg( feature = "legacy-zip" ) ]
278
+ Reduce ( crate :: legacy:: reduce:: ReduceDecoder < R > ) ,
279
+ #[ cfg( feature = "legacy-zip" ) ]
280
+ Implode ( crate :: legacy:: implode:: ImplodeDecoder < R > ) ,
218
281
#[ cfg( feature = "xz" ) ]
219
282
Xz ( Box < lzma_rust2:: XzReader < R > > ) ,
220
283
#[ cfg( feature = "ppmd" ) ]
@@ -338,6 +401,12 @@ impl<R: io::BufRead> io::Read for Decompressor<R> {
338
401
}
339
402
Ppmd :: Initialized ( decompressor) => decompressor. read ( buf) ,
340
403
} ,
404
+ #[ cfg( feature = "legacy-zip" ) ]
405
+ Decompressor :: Shrink ( r) => r. read ( buf) ,
406
+ #[ cfg( feature = "legacy-zip" ) ]
407
+ Decompressor :: Reduce ( r) => r. read ( buf) ,
408
+ #[ cfg( feature = "legacy-zip" ) ]
409
+ Decompressor :: Implode ( r) => r. read ( buf) ,
341
410
}
342
411
}
343
412
}
@@ -346,8 +415,10 @@ impl<R: io::BufRead> Decompressor<R> {
346
415
pub fn new (
347
416
reader : R ,
348
417
compression_method : CompressionMethod ,
349
- #[ cfg( feature = "lzma" ) ] uncompressed_size : u64 ,
350
- #[ cfg( not( feature = "lzma" ) ) ] _uncompressed_size : u64 ,
418
+ #[ cfg( any( feature = "lzma" , feature = "legacy-zip" ) ) ] uncompressed_size : u64 ,
419
+ #[ cfg( not( any( feature = "lzma" , feature = "legacy-zip" ) ) ) ] _uncompressed_size : u64 ,
420
+ #[ cfg( feature = "legacy-zip" ) ] flags : u16 ,
421
+ #[ cfg( not( feature = "legacy-zip" ) ) ] _flags : u16 ,
351
422
) -> crate :: result:: ZipResult < Self > {
352
423
Ok ( match compression_method {
353
424
CompressionMethod :: Stored => Decompressor :: Stored ( reader) ,
@@ -374,6 +445,18 @@ impl<R: io::BufRead> Decompressor<R> {
374
445
}
375
446
#[ cfg( feature = "ppmd" ) ]
376
447
CompressionMethod :: Ppmd => Decompressor :: Ppmd ( Ppmd :: Uninitialized ( Some ( reader) ) ) ,
448
+ #[ cfg( feature = "legacy-zip" ) ]
449
+ CompressionMethod :: Shrink => Decompressor :: Shrink (
450
+ crate :: legacy:: shrink:: ShrinkDecoder :: new ( reader, uncompressed_size) ,
451
+ ) ,
452
+ #[ cfg( feature = "legacy-zip" ) ]
453
+ CompressionMethod :: Reduce ( n) => Decompressor :: Reduce (
454
+ crate :: legacy:: reduce:: ReduceDecoder :: new ( reader, uncompressed_size, n) ,
455
+ ) ,
456
+ #[ cfg( feature = "legacy-zip" ) ]
457
+ CompressionMethod :: Implode => Decompressor :: Implode (
458
+ crate :: legacy:: implode:: ImplodeDecoder :: new ( reader, uncompressed_size, flags) ,
459
+ ) ,
377
460
_ => {
378
461
return Err ( crate :: result:: ZipError :: UnsupportedArchive (
379
462
"Compression method not supported" ,
@@ -402,6 +485,12 @@ impl<R: io::BufRead> Decompressor<R> {
402
485
. ok_or_else ( || io:: Error :: other ( "Reader was not set" ) ) ?,
403
486
Lzma :: Initialized ( decoder) => decoder. into_inner ( ) ,
404
487
} ,
488
+ #[ cfg( feature = "legacy-zip" ) ]
489
+ Decompressor :: Shrink ( r) => r. into_inner ( ) ,
490
+ #[ cfg( feature = "legacy-zip" ) ]
491
+ Decompressor :: Reduce ( r) => r. into_inner ( ) ,
492
+ #[ cfg( feature = "legacy-zip" ) ]
493
+ Decompressor :: Implode ( r) => r. into_inner ( ) ,
405
494
#[ cfg( feature = "xz" ) ]
406
495
Decompressor :: Xz ( r) => r. into_inner ( ) ,
407
496
#[ cfg( feature = "ppmd" ) ]
0 commit comments