Example #1
0
        public static System.IO.Stream OpenStream(long fileSize, System.IO.Stream baseStream)
        {
            int chunkSize;
            var stream = ChunkedDecompressionStream.OpenStreamFast(fileSize, baseStream, out chunkSize,
                                                                   (byte[] data, int offset, int length, int outsize) =>
            {
                byte[] output = new byte[outsize];
                LZ4.LZ4Codec.Decode(data, offset, length, output, 0, outsize, true);
                return(output);
            });

            if (stream != null)
            {
                return(stream);
            }
            return(new LZ4ReaderStream(fileSize, chunkSize, baseStream));
        }
        public static System.IO.Stream OpenStream(long fileSize, System.IO.Stream baseStream)
        {
            int chunkSize;
            var stream = ChunkedDecompressionStream.OpenStreamFast(fileSize, baseStream, out chunkSize,
                                                                   (byte[] data, int offset, int length, int outsize) =>
            {
                IntPtr decompressor;
                if (!s_Decompressors.TryTake(out decompressor))
                {
                    decompressor = CreateDecompressionStream(WindowBits);
                }

                byte[] output = new byte[outsize];
                unsafe
                {
                    fixed(byte *outptr = output)
                    fixed(byte *inptr  = data)
                    {
                        DecompressSetSource(decompressor, (IntPtr)inptr, length);
                        bool finished;
                        DecompressData(decompressor, (IntPtr)outptr, outsize, out finished);
                        if (!finished)
                        {
                            DecompressData(decompressor, (IntPtr)outptr, 0, out finished);
                        }
                    }
                }
                decompressor = ResetDecompressionStream(decompressor);
                if (decompressor != null)
                {
                    s_Decompressors.Add(decompressor);
                }
                return(output);
            });

            if (stream != null)
            {
                return(stream);
            }
            return(new LZHAMReaderStream(fileSize, chunkSize, baseStream));
        }