16 {
17 ZLibNative.CompressionLevel level;
18 int memLevel;
19 switch (compressionLevel)
20 {
22 level = ZLibNative.CompressionLevel.DefaultCompression;
23 memLevel = 8;
24 break;
26 level = ZLibNative.CompressionLevel.BestSpeed;
27 memLevel = 8;
28 break;
30 level = ZLibNative.CompressionLevel.NoCompression;
31 memLevel = 7;
32 break;
34 level = ZLibNative.CompressionLevel.BestCompression;
35 memLevel = 8;
36 break;
37 default:
38 throw new ArgumentOutOfRangeException("compressionLevel");
39 }
40 ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;
41 ZLibNative.ErrorCode errorCode;
42 try
43 {
44 errorCode = ZLibNative.CreateZLibStreamForDeflate(out
_zlibStream, level, windowBits, memLevel, strategy);
45 }
46 catch (Exception innerException)
47 {
49 }
50 switch (errorCode)
51 {
52 case ZLibNative.ErrorCode.Ok:
53 break;
54 case ZLibNative.ErrorCode.MemError:
56 case ZLibNative.ErrorCode.VersionError:
58 case ZLibNative.ErrorCode.StreamError:
60 default:
62 }
63 }
readonly ZLibNative.ZLibStreamHandle _zlibStream
static string ZLibErrorNotEnoughMemory
static string ZLibErrorVersionMismatch
static string ZLibErrorDLLLoadError
static string ZLibErrorUnexpected
static string ZLibErrorIncorrectInitParameters