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); }
protected void btnDownload_Click(object sender, EventArgs e) { Stream outputStream = ExecuteMerge("all", DocumentFormat.Rtf); outputStream.Seek(0, SeekOrigin.Begin); StreamCopyHelper.Copy(outputStream, Response.OutputStream); Response.StatusCode = (int)HttpStatusCode.OK; Response.ContentType = "application/rtf"; Response.AddHeader("Content-Disposition", "attachment; filename=RichEditMailMerge.rtf"); Response.End(); }
private void RefreshPreview(string previewName) { Response.StatusCode = (int)HttpStatusCode.OK; Response.ContentType = "text/html"; Stream outputStream = ExecuteMerge(previewName, DocumentFormat.Html); outputStream.Seek(0, SeekOrigin.Begin); StreamCopyHelper.Copy(outputStream, Response.OutputStream); Response.End(); }
public PatchedStream(Stream input, Stream delta) { this.input = input; this.delta = delta; deltaReader = new BinaryReader(this.delta); ReadHeader(deltaReader); long position = this.delta.Position; commandSummary = ReadCommandSummary(this.delta); this.delta.Seek(position, SeekOrigin.Begin); currentCopyHelper = new StreamCopyHelper(0L, input); }
private int ReadInternalSync(byte[] buffer, int offset, int count) { if (!currentCopyHelper.MoreData) { Command command = ReadCommand(deltaReader); currentCopyHelper = ConstructCopyHelperForCommand(command, input, delta); if (currentCopyHelper == null) { return(0); } } int num = currentCopyHelper.Read(buffer, offset, count); outputPosition += num; return(num); }
public PatchedStream(Stream input, Stream delta) { this.input = input; this.delta = delta; this.deltaReader = new BinaryReader(this.delta); // read and check the header PatchedStream.ReadHeader(this.deltaReader); // Read in all of the commands from the delta to build a table which will tell us the length of the // resulting stream, as well as tell us how to seek into the file var currentPosition = this.delta.Position; this.commandSummary = ReadCommandSummary(this.delta); this.delta.Seek(currentPosition, SeekOrigin.Begin); // starting the current helper with 0 bytes left will force us to immediately read a new command this.currentCopyHelper = new StreamCopyHelper(0, input); }
public PatchedStream(Stream input, Stream delta) { this.input = input; this.delta = delta; this.deltaReader = new BinaryReader(this.delta); // read and check the header PatchedStream.ReadHeader(this.deltaReader); // Read in all of the commands from the delta to build a table which will tell us the length of the // resulting stream, as well as tell us how to seek into the file var currentPosition = this.delta.Position; this.commandSummary = ReadCommandSummary(this.delta); this.delta.Seek(currentPosition, SeekOrigin.Begin); // starting the current helper with 0 bytes left will force us to immediately read a new command this.currentCopyHelper = new StreamCopyHelper(0, input); }
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { // if the current command can't supply any more data, then read a new command if (!this.currentCopyHelper.MoreData) { // read the next command from the delta stream var command = ReadCommand(this.deltaReader); // construct a copy helper to run that command this.currentCopyHelper = ConstructCopyHelperForCommand(command, this.input, this.delta); if (this.currentCopyHelper == null) { // if it's null, that means we reached the end token return 0; } } // now read the data based on the copy helper int bytesRead = await this.currentCopyHelper.ReadAsync(buffer, offset, count, cancellationToken); this.outputPosition += bytesRead; return bytesRead; }
public override async Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { // if the current command can't supply any more data, then read a new command if (!this.currentCopyHelper.MoreData) { // read the next command from the delta stream var command = ReadCommand(this.deltaReader); // construct a copy helper to run that command this.currentCopyHelper = ConstructCopyHelperForCommand(command, this.input, this.delta); if (this.currentCopyHelper == null) { // if it's null, that means we reached the end token return(0); } } // now read the data based on the copy helper int bytesRead = await this.currentCopyHelper.ReadAsync(buffer, offset, count, cancellationToken); this.outputPosition += bytesRead; return(bytesRead); }
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); }
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; }