public override long Seek(long offset, SeekOrigin origin) { long newPosition = StreamHelpers.ComputeNewPosition(offset, origin, this.Length, this.Position); if (newPosition < SignatureStream.HeaderLength) { this.InitializeHeader(); this.bufferStream.Seek(newPosition, SeekOrigin.Begin); } else { // if we are in the main section of the file, we calculate which block we are in // then we seek to the point at the start of that block in the source file // we refill the buffer and seek into it the remainder bytes long adjustedPosition = newPosition - SignatureStream.HeaderLength; int blockSize = (4 + this.settings.StrongSumLength); long remainderBytes; long blockNumber = Math.DivRem(adjustedPosition, blockSize, out remainderBytes); this.inputStream.Seek(blockNumber * this.settings.BlockLength, SeekOrigin.Begin); this.FillBuffer(); // this reads the next block and computes it's hash this.bufferStream.Seek(remainderBytes, SeekOrigin.Begin); } this.currentPosition = newPosition; return(this.currentPosition); }
public override long Seek(long offset, SeekOrigin origin) { long num = StreamHelpers.ComputeNewPosition(offset, origin, Length, Position); long num2 = 0L; int i; for (i = 0; i < commandSummary.Count; i++) { long num3 = num2; CommandPosition commandPosition = commandSummary[i]; long num4 = num3 + commandPosition.Command.Length; if (num4 > num) { break; } num2 = num4; } if (i == commandSummary.Count) { throw new ArgumentException("The specified offset is past the end of the stream"); } delta.Seek(commandSummary[i].DeltaStartPosition, SeekOrigin.Begin); Command command = ReadCommand(deltaReader); currentCopyHelper = ConstructCopyHelperForCommand(command, input, delta); currentCopyHelper.SeekForward(num - num2); outputPosition = num; return(num); }
public override long Seek(long offset, SeekOrigin origin) { long num = StreamHelpers.ComputeNewPosition(offset, origin, Length, Position); if (num < 12) { InitializeHeader(); bufferStream.Seek(num, SeekOrigin.Begin); } else { long a = num - 12; int num2 = 4 + settings.StrongSumLength; long result; long num3 = Math.DivRem(a, num2, out result); inputStream.Seek(num3 * settings.BlockLength, SeekOrigin.Begin); FillBuffer(); bufferStream.Seek(result, SeekOrigin.Begin); } currentPosition = num; return(currentPosition); }
public override long Seek(long offset, SeekOrigin origin) { long newPosition = StreamHelpers.ComputeNewPosition(offset, origin, this.Length, this.Position); // search until we find the command just before this position long runningTotal = 0; int i; for (i = 0; i < this.commandSummary.Count; i++) { // if this is the first command that takes us past the desired position long newTotal = runningTotal + this.commandSummary[i].Command.Length; if (newTotal > newPosition) { break; } runningTotal = newTotal; } if (i == this.commandSummary.Count) { throw new ArgumentException("The specified offset is past the end of the stream"); } // seek to the point that that command starts this.delta.Seek(this.commandSummary[i].DeltaStartPosition, SeekOrigin.Begin); // now read that command in var command = ReadCommand(this.deltaReader); // construct a copy helper to run that command this.currentCopyHelper = ConstructCopyHelperForCommand(command, this.input, this.delta); // finally seek into the copy helper for whatever bytes are left over this.currentCopyHelper.SeekForward(newPosition - runningTotal); this.outputPosition = newPosition; return(newPosition); }