Ejemplo n.º 1
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            // Find the correct part
            long offsetFromStart = 0;

            switch (origin)
            {
            case SeekOrigin.Begin:
                offsetFromStart = offset;
                break;

            case SeekOrigin.Current:
                offsetFromStart = Position + offset;
                break;

            case SeekOrigin.End:
                offsetFromStart = length + offset;
                break;
            }

            // Use this to calculate the correct file
            PartialFile part = FindPartAt(offsetFromStart);

            Debug.WriteLine("Seeking to {0} from {1}, found in part {2}, currentpart {3}", offset, origin, part.Number,
                            currentPart.Number);

            if (!currentPart.Equals(part))
            {
                if (!OpenPart(part))
                {
                    positionInPart = currentPart.Length;
                    internalStream.Seek(0, SeekOrigin.End);
                    _position = currentPart.StartPosition + currentPart.Length;
                    return(_position);
                }
            }

            positionInPart = offsetFromStart - currentPart.StartPosition;
            internalStream.Seek(positionInPart, SeekOrigin.Begin);
            _position = offsetFromStart;

            return(_position);
        }
Ejemplo n.º 2
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            long offsetFromStart = 0;

            switch (origin)
            {
            case SeekOrigin.Begin:
                offsetFromStart = offset;
                break;

            case SeekOrigin.Current:
                offsetFromStart = Position + offset;
                break;

            case SeekOrigin.End:
                offsetFromStart = length + offset;
                break;
            }

            // Use this to calculate the correct file
            PartialFile part = FindPartAt(offsetFromStart);

            if (!_currentPart.Equals(part))
            {
                if (!OpenPart(part))
                {
                    positionInPart = _currentPart.Length;
                    _current.Seek(0, SeekOrigin.End);
                    _position = _currentPart.StartPosition + _currentPart.Length;
                    return(_position);
                }
            }

            positionInPart = offsetFromStart - _currentPart.StartPosition;
            _current.Seek(positionInPart, SeekOrigin.Begin);
            _position = offsetFromStart;

            return(_position);
        }