Exemplo n.º 1
0
        private unsafe int ReadBlock()
        {
            FlushPeek();

            var blockLength = (int)Peek32();

            if (blockLength == 0)
            {
                if (_frameInfo.ContentChecksum)
                {
                    Peek32();
                }
                CloseFrame();
                return(0);
            }

            var uncompressed = (blockLength & 0x80000000) != 0;

            blockLength &= 0x7FFFFFFF;

            PeekN(_buffer, 0, blockLength);

            if (_frameInfo.BlockChecksum)
            {
                Peek32();

                fixed(byte *bufferP = _buffer)
                return(uncompressed
                                        ? _decoder.Inject(bufferP, blockLength)
                                        : _decoder.Decode(bufferP, blockLength));
        }
Exemplo n.º 2
0
		private unsafe int ReadBlock()
		{
			Read0();

			int blockLength = (int) Read32();
			if (blockLength == 0)
			{
				if (_frameInfo.ContentChecksum)
					Read32();
				CloseFrame();
				return 0;
			}

			bool uncompressed = (blockLength & 0x80000000) != 0;
			blockLength &= 0x7FFFFFFF;

			ReadN(_buffer, 0, blockLength);

			if (_frameInfo.BlockChecksum)
				Read32();

			fixed (byte* bufferPtr = _buffer)
            {
                return uncompressed
                    ? _decoder.Inject(bufferPtr, blockLength)
                    : _decoder.Decode(bufferPtr, blockLength);
            }
        }
Exemplo n.º 3
0
        private unsafe int ReadBlock()
        {
            Read0();

            var blockLength = (int)Read32();

            if (blockLength == 0)
            {
                if (_frameInfo.ContentChecksum)
                {
                    Read32();
                }
                CloseFrame();
                return(0);
            }

            var uncompressed = (blockLength & 0x80000000) != 0;

            blockLength &= 0x7FFFFFFF;

            // keep reading from the stream until it gives us every byte we've asked for
            for (var blockCursor = 0; blockCursor < blockLength;)
            {
                var advance = _inner.Read(_buffer, blockCursor, blockLength - blockCursor);
                if (advance == 0)
                {
                    break;                     // Note: this probably means the stream is truncated and could just be a throw instead
                }
                blockCursor += advance;
            }

            if (_frameInfo.BlockChecksum)
            {
                Read32();

                fixed(byte *bufferP = _buffer)
                return(uncompressed
                                        ? _decoder.Inject(bufferP, blockLength)
                                        : _decoder.Decode(bufferP, blockLength));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Inject already decompressed block and caches it in decoder.
 /// Used with uncompressed-yet-chained blocks and pre-made dictionaries.
 /// See <see cref="ILZ4Decoder.Inject"/>.
 /// </summary>
 /// <param name="decoder">Decoder.</param>
 /// <param name="buffer">Uncompressed block.</param>
 /// <param name="offset">Offset in uncompressed block.</param>
 /// <param name="length">Length of uncompressed block.</param>
 /// <returns>Number of decoded bytes.</returns>
 public static unsafe int Inject(
     this ILZ4Decoder decoder, byte[] buffer, int offset, int length)
 {
     fixed(byte *bufferP = buffer)
     return(decoder.Inject(bufferP + offset, length));
 }
 private int InjectOrDecode(int blockLength, bool uncompressed) =>
 uncompressed
                         ? _decoder.Inject(_buffer, 0, blockLength)
                         : _decoder.Decode(_buffer, 0, blockLength);