1
1
// Copyright (c) Microsoft. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
+ using System . Diagnostics ;
4
5
using System . Diagnostics . Contracts ;
5
6
using System . Runtime . InteropServices ;
6
7
using System . Security ;
7
- using System . Text ;
8
8
9
9
namespace System . IO . Compression
10
10
{
@@ -221,7 +221,6 @@ public enum State { NotInitialized, InitializedForDeflate, InitializedForInflate
221
221
222
222
223
223
public ZLibStreamHandle ( )
224
-
225
224
: base ( new IntPtr ( - 1 ) , true )
226
225
{
227
226
_zStream = new ZStream ( ) ;
@@ -236,7 +235,7 @@ public ZLibStreamHandle()
236
235
public override bool IsInvalid
237
236
{
238
237
[ SecurityCritical ]
239
- get { return DangerousGetHandle ( ) == new IntPtr ( - 1 ) ; }
238
+ get { return handle == new IntPtr ( - 1 ) ; }
240
239
}
241
240
242
241
public State InitializationState
@@ -250,9 +249,6 @@ public State InitializationState
250
249
[ SecurityCritical ]
251
250
protected override bool ReleaseHandle ( )
252
251
{
253
- // We are in a finalizer thread at the end of the App and the finalization of the dynamically loaded ZLib happend
254
- // to be scheduled first. In such case we have no hope of properly freeing zStream. If the process is dying - we
255
- // do not care. In other cases somethign went badly wrong anyway:
256
252
switch ( InitializationState )
257
253
{
258
254
case State . NotInitialized : return true ;
@@ -412,33 +408,11 @@ public ErrorCode InflateEnd()
412
408
public string GetErrorMessage ( )
413
409
{
414
410
// This can work even after XxflateEnd().
415
-
416
- if ( ZNullPtr . Equals ( _zStream . msg ) )
417
- return String . Empty ;
418
-
419
- unsafe
420
- {
421
- StringBuilder sb = new StringBuilder ( ) ;
422
- SByte * pMessage = ( SByte * ) _zStream . msg ;
423
- char c ;
424
- do
425
- {
426
- c = ( char ) * pMessage ;
427
- pMessage ++ ;
428
- sb . Append ( c ) ;
429
- } while ( ( sbyte ) c != 0 ) ;
430
-
431
- return sb . ToString ( ) ;
432
- }
411
+ return _zStream . msg != ZNullPtr ? Marshal . PtrToStringAnsi ( _zStream . msg ) : string . Empty ;
433
412
}
434
413
435
414
#endregion // Expose ZLib functions for use by user / Fx code (add more as required)
436
415
437
- [ SecurityCritical ]
438
- internal static Int32 ZLibCompileFlags ( )
439
- {
440
- return Interop . zlib . zlibCompileFlags ( ) ;
441
- }
442
416
} // class ZLibStreamHandle
443
417
444
418
#endregion // ZLib Stream Handle type
@@ -447,15 +421,6 @@ internal static Int32 ZLibCompileFlags()
447
421
#region public factory methods for ZLibStreamHandle
448
422
449
423
450
- [ SecurityCritical ]
451
- public static ErrorCode CreateZLibStreamForDeflate ( out ZLibStreamHandle zLibStreamHandle )
452
- {
453
- return CreateZLibStreamForDeflate ( out zLibStreamHandle ,
454
- CompressionLevel . DefaultCompression , Deflate_DefaultWindowBits ,
455
- Deflate_DefaultMemLevel , CompressionStrategy . DefaultStrategy ) ;
456
- }
457
-
458
-
459
424
[ SecurityCritical ]
460
425
public static ErrorCode CreateZLibStreamForDeflate ( out ZLibStreamHandle zLibStreamHandle ,
461
426
CompressionLevel level , int windowBits , int memLevel , CompressionStrategy strategy )
@@ -465,13 +430,6 @@ public static ErrorCode CreateZLibStreamForDeflate(out ZLibStreamHandle zLibStre
465
430
}
466
431
467
432
468
- [ SecurityCritical ]
469
- public static ErrorCode CreateZLibStreamForInflate ( out ZLibStreamHandle zLibStreamHandle )
470
- {
471
- return CreateZLibStreamForInflate ( out zLibStreamHandle , Deflate_DefaultWindowBits ) ;
472
- }
473
-
474
-
475
433
[ SecurityCritical ]
476
434
public static ErrorCode CreateZLibStreamForInflate ( out ZLibStreamHandle zLibStreamHandle , int windowBits )
477
435
{
@@ -481,15 +439,5 @@ public static ErrorCode CreateZLibStreamForInflate(out ZLibStreamHandle zLibStre
481
439
482
440
#endregion // public factory methods for ZLibStreamHandle
483
441
484
-
485
- #region public utility APIs
486
-
487
- [ SecurityCritical ]
488
- public static Int32 ZLibCompileFlags ( )
489
- {
490
- return ZLibStreamHandle . ZLibCompileFlags ( ) ;
491
- }
492
- #endregion // public utility APIs
493
-
494
442
} // internal class ZLibNative
495
443
} // namespace System.IO.Compression
0 commit comments