private ZLibNative.ErrorCode Inflate(ZLibNative.FlushCode flushCode) { ZLibNative.ErrorCode errC; try { errC = _zlibStream.Inflate(flushCode); } catch (Exception cause) // could not load the Zlib DLL correctly { throw new ZLibException("SR.ZLibErrorDLLLoadError", cause); } switch (errC) { case ZLibNative.ErrorCode.Ok: // progress has been made inflating case ZLibNative.ErrorCode.StreamEnd: // The end of the input stream has been reached return(errC); case ZLibNative.ErrorCode.BufError: // No room in the output buffer - inflate() can be called again with more space to continue return(errC); case ZLibNative.ErrorCode.MemError: // Not enough memory to complete the operation throw new ZLibException("SR.ZLibErrorNotEnoughMemory", "inflate_", (int)errC, _zlibStream.GetErrorMessage()); case ZLibNative.ErrorCode.DataError: // The input data was corrupted (input stream not conforming to the zlib format or incorrect check value) throw new InvalidDataException("SR.UnsupportedCompression"); case ZLibNative.ErrorCode.StreamError: //the stream structure was inconsistent (for example if next_in or next_out was NULL), throw new ZLibException("SR.ZLibErrorInconsistentStream", "inflate_", (int)errC, _zlibStream.GetErrorMessage()); default: throw new ZLibException("SR.ZLibErrorUnexpected", "inflate_", (int)errC, _zlibStream.GetErrorMessage()); } }
internal static unsafe ZLibNative.ErrorCode Deflate(ref ZLibNative.ZStream stream, ZLibNative.FlushCode flush) { fixed (ZLibNative.ZStream* streamBytes = &stream) { byte* pBytes = (byte*) streamBytes; return (ZLibNative.ErrorCode) deflate(pBytes, (int) flush); } }
private ZLibNative.ErrorCode Deflate(ZLibNative.FlushCode flushCode) { var errorCode = m_handle.Deflate(flushCode); switch (errorCode) { case ZLibNative.ErrorCode.Ok: case ZLibNative.ErrorCode.StreamEnd: case ZLibNative.ErrorCode.BufError: return(errorCode); case ZLibNative.ErrorCode.StreamError: throw new IOException("The stream state of the underlying compression routine is inconsistent."); default: throw new IOException($"The underlying compression routine returned an unexpected error code {errorCode}."); } }
private ZLibNative.ErrorCode Inflate(ZLibNative.FlushCode flushCode) { var errorCode = m_handle.Inflate(flushCode); switch (errorCode) { case ZLibNative.ErrorCode.Ok: // progress has been made inflating case ZLibNative.ErrorCode.StreamEnd: // The end of the input stream has been reached case ZLibNative.ErrorCode.BufError: // No room in the output buffer - inflate() can be called again with more space to continue return(errorCode); case ZLibNative.ErrorCode.MemError: // Not enough memory to complete the operation throw new IOException("The underlying compression routine could not reserve sufficient memory."); case ZLibNative.ErrorCode.DataError: // The input data was corrupted (input stream not conforming to the zlib format or incorrect check value) throw new IOException("The archive entry was compressed using an unsupported compression method."); case ZLibNative.ErrorCode.StreamError: //the stream structure was inconsistent (for example if next_in or next_out was NULL), throw new IOException("The stream state of the underlying compression routine is inconsistent."); default: throw new IOException($"The underlying compression routine returned an unexpected error code {errorCode}."); } }
internal static extern ZLibNative.ErrorCode Inflate(ref ZLibNative.ZStream stream, ZLibNative.FlushCode flush);
/// <summary> /// Wrapper around the ZLib inflate function, configuring the stream appropriately. /// </summary> private unsafe ZLibNative.ErrorCode ReadInflateOutput(IntPtr bufPtr, int length, ZLibNative.FlushCode flushCode, out int bytesRead) { lock (_syncLock) { _zlibStream.NextOut = bufPtr; _zlibStream.AvailOut = (uint)length; ZLibNative.ErrorCode errC = Inflate(flushCode); bytesRead = length - (int)_zlibStream.AvailOut; return(errC); } }
internal static unsafe partial ZLibNative.ErrorCode Inflate(ZLibNative.ZStream *stream, ZLibNative.FlushCode flush);
public ZLibNative.ErrorCode Inflate(ZLibNative.FlushCode flush) { this.EnsureNotDisposed(); this.EnsureState(ZLibNative.ZLibStreamHandle.State.InitializedForInflate); return(ZLibNative.ZLibStreamHandle.NativeZLibDLLStub.inflateDelegate(ref this.zStream, flush)); }
internal static unsafe ZLibNative.ErrorCode Inflate(ref ZLibNative.ZStream stream, ZLibNative.FlushCode flush) { fixed(ZLibNative.ZStream *streamBytes = &stream) { return(Inflate((Byte *)streamBytes, (Int32)flush)); } }
/// <summary> /// Translates the given byte array to a GCHandle so that it can be passed to the ZLib /// Inflate function, then returns the result of that call. /// </summary> private unsafe ZLibNative.ErrorCode ReadInflateOutput(byte[] outputBuffer, int offset, int length, ZLibNative.FlushCode flushCode, out int bytesRead) { lock (_syncLock) { fixed(byte *bufPtr = outputBuffer) { _zlibStream.NextOut = (IntPtr)bufPtr + offset; _zlibStream.AvailOut = (uint)length; ZLibNative.ErrorCode errC = Inflate(flushCode); bytesRead = length - (int)_zlibStream.AvailOut; return(errC); } } }
internal static extern unsafe ZLibNative.ErrorCode Inflate(ZLibNative.ZStream *stream, ZLibNative.FlushCode flush);