예제 #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (DecompressEnumerator == null)
            {
                DecompressEnumerator = Decompress(compressedStream).GetEnumerator();
            }

            int i;

            for (i = 0; i < count; i++)
            {
                DecompressEnumerator.MoveNext();
                buffer[offset + i] = DecompressEnumerator.Current;
            }

            return(i);
        }
예제 #2
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            if (origin == SeekOrigin.Current && offset < 0)
            {
                origin = SeekOrigin.Begin;
                offset = decompressedPosition + offset;
            }

            if (origin == SeekOrigin.Begin)
            {
                decompressedPosition      = 0;
                compressedStream.Position = compressedStartPosition;
                DecompressEnumerator      = Decompress(compressedStream).GetEnumerator();

                for (int i = 0; i < offset; i++)
                {
                    DecompressEnumerator.MoveNext();
                }

                return(decompressedPosition);
            }

            if (origin == SeekOrigin.Current)
            {
                for (int i = 0; i < offset; i++)
                {
                    DecompressEnumerator.MoveNext();
                }

                return(decompressedPosition);
            }

            if (origin == SeekOrigin.End)
            {
                var desiredPosition = decompressedLength + offset;
                return(Seek(desiredPosition, SeekOrigin.Begin));
            }

            return(-1);
        }