Exemplo n.º 1
0
        unsafe void Write(byte *buffer, int count, LZMAAction action)
        {
            if (_mode == CompressionMode.Decompress)
            {
                throw new NotSupportedException("Can't write on a decompress stream!");
            }

            _wasWrittenTo = true;

            _zstream->avail_in = (IntPtr)count;
            _zstream->next_in  = buffer;

            do
            {
                var result = LZMANative.lzma_code(_zstream, action);

                var avail_out = _zstream->avail_out.ToInt32();
                if (avail_out < BufferSize)
                {
                    var outSize = BufferSize - avail_out;
                    _compressedStream.Write(_tmpBuffer, 0, outSize);
                    _zstream->next_out  = _tmpBufferPtr;
                    _zstream->avail_out = (IntPtr)BufferSize;
                }


                // Translate erros into specific exceptions
                switch (result)
                {
                case LZMAStatus.LZMA_OK:
                    continue;

                case LZMAStatus.LZMA_STREAM_END:
                    return;

                case LZMAStatus.LZMA_MEM_ERROR:
                case LZMAStatus.LZMA_MEMLIMIT_ERROR:
                    throw new OutOfMemoryException("liblzma return code: " + result);

                default:
                    throw new Exception("liblzma return code: " + result);
                }
            } while ((_zstream->avail_in.ToInt32() > 0) || action == LZMAAction.LZMA_FINISH);
        }
 public static extern unsafe LZMAStatus lzma_code(LZMAStreamNative* strm, LZMAAction action);
    private unsafe void Write(byte* buffer, int count, LZMAAction action)
    {
      if (_mode == CompressionMode.Decompress)
        throw new NotSupportedException("Can't write on a decompress stream!");

      _wasWrittenTo = true;

      _zstream->avail_in = (IntPtr)count;
      _zstream->next_in = buffer;

      do {
        var result = LZMANative.lzma_code(_zstream, action);

        var avail_out = _zstream->avail_out.ToInt32();
        if (avail_out < BufferSize) {
          var outSize = BufferSize - avail_out;
          _compressedStream.Write(_tmpBuffer, 0, outSize);
          _zstream->next_out = _tmpBufferPtr;
          _zstream->avail_out = (IntPtr) BufferSize;
        }


        // Translate erros into specific exceptions
        switch (result) {
          case LZMAStatus.LZMA_OK:
            continue;
          case LZMAStatus.LZMA_STREAM_END:
            return;
          case LZMAStatus.LZMA_MEM_ERROR:
          case LZMAStatus.LZMA_MEMLIMIT_ERROR:
            throw new OutOfMemoryException("liblzma return code: " + result);
          default:
            throw new Exception("liblzma return code: " + result);
        }
      } while ((_zstream->avail_in.ToInt32() > 0) || action == LZMAAction.LZMA_FINISH);

    }
Exemplo n.º 4
0
 public static extern unsafe LZMAStatus lzma_code(LZMAStreamNative *strm, LZMAAction action);