예제 #1
0
 public LzhamStream(Stream stream, CompressionParameters mode, bool leaveOpen)
 {
     if (stream == null)
         throw new ArgumentNullException(nameof(stream));
     if (!stream.CanWrite)
         throw new ArgumentException("The base stream is not writeable", nameof(stream));
     _stream = stream;
     _leaveOpen = leaveOpen;
     _buffer = new byte[DefaultBufferSize];
     _compressionHandle = LzhamInterop.CompressInit(mode);
     if (_compressionHandle.IsInvalid)
     {
         throw new ApplicationException("Could not initialize compression stream with specified parameters");
     }
 }
예제 #2
0
 private static extern unsafe int lzham_compress2(CompressionHandle state, byte* inBuf, ref IntPtr inBufSize, byte* outBuf,
     ref IntPtr outBufSize, Flush flushType);
예제 #3
0
 private static extern unsafe int lzham_compress(CompressionHandle state, byte* inBuf, ref IntPtr inBufSize, byte* outBuf,
     ref IntPtr outBufSize, int noMoreInputBytesFlag);
예제 #4
0
 public static unsafe CompressStatus Compress2(CompressionHandle state, byte[] inBuf, ref int inBufSize, int inBufOffset, byte[] outBuf, ref int outBufSize, int outBufOffset, Flush flushType)
 {
     if (inBufOffset + inBufSize > inBuf.Length)
     {
         throw new ArgumentException("Offset plus count is larger than the length of array", nameof(inBuf));
     }
     if (outBufOffset + outBufSize > outBuf.Length)
     {
         throw new ArgumentException("Offset plus count is larger than the length of array", nameof(outBuf));
     }
     fixed (byte* inBytes = inBuf)
     fixed (byte* outBytes = outBuf)
     {
         IntPtr inSize = new IntPtr(inBufSize);
         IntPtr outSize = new IntPtr(outBufSize);
         CompressStatus result = (CompressStatus)lzham_compress2(state, inBytes+inBufOffset, ref inSize, outBytes+outBufOffset, ref outSize, flushType);
         inBufSize = inSize.ToInt32();
         outBufSize = outSize.ToInt32();
         return result;
     }
 }
예제 #5
0
 public static CompressionHandle CompressReinit(CompressionHandle state)
 {
     return lzham_compress_reinit(state);
 }
예제 #6
0
 private static extern CompressionHandle lzham_compress_reinit(CompressionHandle state);