Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created March 11, 2013 08:58
Show Gist options
  • Save thecodejunkie/5132898 to your computer and use it in GitHub Desktop.
Save thecodejunkie/5132898 to your computer and use it in GitHub Desktop.
RequestStream modification
public RequestStream(Stream stream, long expectedLength, long thresholdLength, bool disableStreamSwitching)
{
this.thresholdLength = thresholdLength;
this.disableStreamSwitching = disableStreamSwitching;
this.stream = stream ?? this.CreateDefaultMemoryStream(expectedLength);
ThrowExceptionIfCtorParametersWereInvalid(this.stream, expectedLength, this.thresholdLength);
this.MoveStreamOutOfMemoryIfExpectedLengthExceedExpectedLength(expectedLength);
this.MoveStreamOutOfMemoryIfContentsLengthExceedThresholdAndSwitchingIsEnabled();
if(!this.stream.CanSeek)
{
this.stream =
this.CreateDefaultMemoryStream(expectedLength);
stream.CopyTo(this.stream);
}
this.stream.Position = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment