Skip to content

Commit a4bec6f

Browse files
Merge branch 'zippo227-master'
2 parents a12a2ef + df598a5 commit a4bec6f

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

src/ICSharpCode.SharpZipLib/Zip/Compression/Deflater.cs

+39-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,45 @@ public class Deflater
7777
/// There is no need to use this constant at all.
7878
/// </summary>
7979
public const int DEFLATED = 8;
80-
#endregion
81-
#region Local Constants
82-
private const int IS_SETDICT = 0x01;
80+
#endregion
81+
#region Public Enum
82+
83+
/// <summary>
84+
/// Compression Level as an enum for safer use
85+
/// </summary>
86+
public enum CompressionLevel
87+
{
88+
/// <summary>
89+
/// The best and slowest compression level. This tries to find very
90+
/// long and distant string repetitions.
91+
/// </summary>
92+
BEST_COMPRESSION = Deflater.BEST_COMPRESSION,
93+
94+
/// <summary>
95+
/// The worst but fastest compression level.
96+
/// </summary>
97+
BEST_SPEED = Deflater.BEST_SPEED,
98+
99+
/// <summary>
100+
/// The default compression level.
101+
/// </summary>
102+
DEFAULT_COMPRESSION = Deflater.DEFAULT_COMPRESSION,
103+
104+
/// <summary>
105+
/// This level won't compress at all but output uncompressed blocks.
106+
/// </summary>
107+
NO_COMPRESSION = Deflater.NO_COMPRESSION,
108+
109+
/// <summary>
110+
/// The compression method. This is the only method supported so far.
111+
/// There is no need to use this constant at all.
112+
/// </summary>
113+
DEFLATED = Deflater.DEFLATED
114+
}
115+
116+
#endregion
117+
#region Local Constants
118+
private const int IS_SETDICT = 0x01;
83119
private const int IS_FLUSHING = 0x04;
84120
private const int IS_FINISHING = 0x08;
85121

src/ICSharpCode.SharpZipLib/Zip/FastZip.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.IO;
33
using ICSharpCode.SharpZipLib.Core;
4+
using ICSharpCode.SharpZipLib.Zip.Compression;
5+
using static ICSharpCode.SharpZipLib.Zip.Compression.Deflater;
46

57
namespace ICSharpCode.SharpZipLib.Zip
68
{
@@ -170,6 +172,7 @@ public enum Overwrite
170172
/// </summary>
171173
Always
172174
}
175+
173176
#endregion
174177

175178
#region Constructors
@@ -263,13 +266,22 @@ public bool RestoreDateTimeOnExtract {
263266
}
264267

265268
/// <summary>
266-
/// Get/set a value indicating wether file attributes should
269+
/// Get/set a value indicating whether file attributes should
267270
/// be restored during extract operations
268271
/// </summary>
269272
public bool RestoreAttributesOnExtract {
270273
get { return restoreAttributesOnExtract_; }
271274
set { restoreAttributesOnExtract_ = value; }
272275
}
276+
277+
/// <summary>
278+
/// Get/set the Compression Level that will be used
279+
/// when creating the zip
280+
/// </summary>
281+
public Deflater.CompressionLevel CompressionLevel{
282+
get { return compressionLevel_; }
283+
set { compressionLevel_ = value; }
284+
}
273285
#endregion
274286

275287
#region Delegates
@@ -322,6 +334,8 @@ public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse,
322334

323335
using (outputStream_ = new ZipOutputStream(outputStream)) {
324336

337+
outputStream_.SetLevel((int)CompressionLevel);
338+
325339
if (password_ != null) {
326340
outputStream_.Password = password_;
327341
}
@@ -640,8 +654,9 @@ static bool NameIsValid(string name)
640654
IEntryFactory entryFactory_ = new ZipEntryFactory();
641655
INameTransform extractNameTransform_;
642656
UseZip64 useZip64_ = UseZip64.Dynamic;
657+
CompressionLevel compressionLevel_ = CompressionLevel.DEFAULT_COMPRESSION;
643658

644-
string password_;
659+
string password_;
645660

646661
#endregion
647662
}

0 commit comments

Comments
 (0)