private ZErrorCode ReadDeflateOutput(byte[] outputBuffer, ZFlushCode flushCode, out int bytesRead)
        {
            lock (syncLock) {
                GCHandle outputBufferHndl = GCHandle.Alloc(outputBuffer, GCHandleType.Pinned);

                try {
                    _zlibStream.NextOut  = outputBufferHndl.AddrOfPinnedObject();
                    _zlibStream.AvailOut = (uint)outputBuffer.Length;

                    ZErrorCode errC = Deflate(flushCode);
                    bytesRead = outputBuffer.Length - (int)_zlibStream.AvailOut;

                    return(errC);
                } finally {
                    outputBufferHndl.Free();
                }
            }
        }
Beispiel #2
0
        private unsafe ZErrorCode ReadDeflateOutput(byte[] outputBuffer, ZFlushCode flushCode, out int bytesRead)
        {
            Debug.Assert(outputBuffer?.Length > 0);

            lock (SyncLock)
            {
                fixed(byte *bufPtr = &outputBuffer[0])
                {
                    _zlibStream.NextOut  = (IntPtr)bufPtr;
                    _zlibStream.AvailOut = (uint)outputBuffer.Length;

                    ZErrorCode errC = Deflate(flushCode);

                    bytesRead = outputBuffer.Length - (int)_zlibStream.AvailOut;

                    return(errC);
                }
            }
        }
Beispiel #3
0
 private void Init(string zlibErrorContext, ZErrorCode zlibErrorCode, string zlibErrorMessage) {
     this.zlibErrorContext = zlibErrorContext;
     this.zlibErrorCode = zlibErrorCode;
     this.zlibErrorMessage = zlibErrorMessage;
 }
Beispiel #4
0
 /// <summary>
 /// This is the preferred constructor to use.
 /// The other constructors are provided for compliance to Fx design guidelines.
 /// </summary>
 /// <param name="message">A (localised) human readable error description.</param>
 /// <param name="zlibErrorContext">A description of the context within zlib where the error occurred (e.g. the function name).</param>
 /// <param name="zlibErrorCode">The error code returned by a ZLib function that caused this exception.</param>
 /// <param name="zlibErrorMessage">The string provided by ZLib as error information (unlocalised).</param>
 public ZLibException(string message, string zlibErrorContext, int zlibErrorCode, string zlibErrorMessage) : base(message)
 {
     _zlibErrorContext = zlibErrorContext;
     _zlibErrorCode    = (ZErrorCode)zlibErrorCode;
     _zlibErrorMessage = zlibErrorMessage;
 }