示例#1
0
        private ZErrorCode Deflate(ZFlushCode flushCode)
        {
            ZErrorCode errC;

            try
            {
                errC = _zlibStream.Deflate(flushCode);
            }
            catch (Exception cause)
            {
                throw new ZLibException(SR.ZLibErrorDLLLoadError, cause);
            }

            switch (errC)
            {
            case ZErrorCode.Ok:
            case ZErrorCode.StreamEnd:
                return(errC);

            case ZErrorCode.BufError:
                return(errC);     // This is a recoverable error

            case ZErrorCode.StreamError:
                throw new ZLibException(SR.ZLibErrorInconsistentStream, "deflate", (int)errC, _zlibStream.GetErrorMessage());

            default:
                throw new ZLibException(SR.ZLibErrorUnexpected, "deflate", (int)errC, _zlibStream.GetErrorMessage());
            }
        }
示例#2
0
        private unsafe ZErrorCode ReadDeflateOutput(IntPtr buffer, int count, ZFlushCode flushCode, out int bytesRead)
        {
            lock (_syncLock)
            {
                _zlibStream.NextOut  = buffer;
                _zlibStream.AvailOut = (uint)count;

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

                return(errC);
            }
        }
示例#3
0
        private unsafe ZErrorCode ReadDeflateOutput(byte[] outputBuffer, ZFlushCode flushCode, out int bytesRead)
        {
            lock (SyncLock)
            {
                fixed(byte *bufPtr = outputBuffer)
                {
                    _zlibStream.NextOut  = (IntPtr)bufPtr;
                    _zlibStream.AvailOut = (uint)outputBuffer.Length;

                    ZErrorCode errC = Deflate(flushCode);

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

                    return(errC);
                }
            }
        }
        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();
                }
            }
        }
示例#5
0
        private ZErrorCode Deflate(ZFlushCode flushCode)
        {
            ZErrorCode errC;
            try
            {
                errC = _zlibStream.Deflate(flushCode);
            }
            catch (Exception cause)
            {
                throw new ZLibException(SR.ZLibErrorDLLLoadError, cause);
            }

            switch (errC)
            {
                case ZErrorCode.Ok:
                case ZErrorCode.StreamEnd:
                    return errC;

                case ZErrorCode.BufError:
                    return errC;  // This is a recoverable error

                case ZErrorCode.StreamError:
                    throw new ZLibException(SR.ZLibErrorInconsistentStream, "deflate", (int)errC, _zlibStream.GetErrorMessage());

                default:
                    throw new ZLibException(SR.ZLibErrorUnexpected, "deflate", (int)errC, _zlibStream.GetErrorMessage());
            }
        }
示例#6
0
        private unsafe ZErrorCode ReadDeflateOutput(byte[] outputBuffer, ZFlushCode flushCode, out int bytesRead)
        {
            lock (_syncLock)
            {
                fixed (byte* bufPtr = outputBuffer)
                {
                    _zlibStream.NextOut = (IntPtr)bufPtr;
                    _zlibStream.AvailOut = (uint)outputBuffer.Length;

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

                    return errC;
                }
            }
        }
示例#7
0
    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();
            }
        }
    }