Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

45 lines
1.2 KiB
C#

namespace System.Web.Mvc {
using System;
using System.IO;
using System.Web;
public class FileStreamResult : FileResult {
// default buffer size as defined in BufferedStream type
private const int _bufferSize = 0x1000;
public FileStreamResult(Stream fileStream, string contentType)
: base(contentType) {
if (fileStream == null) {
throw new ArgumentNullException("fileStream");
}
FileStream = fileStream;
}
public Stream FileStream {
get;
private set;
}
protected override void WriteFile(HttpResponseBase response) {
// grab chunks of data and write to the output stream
Stream outputStream = response.OutputStream;
using (FileStream) {
byte[] buffer = new byte[_bufferSize];
while (true) {
int bytesRead = FileStream.Read(buffer, 0, _bufferSize);
if (bytesRead == 0) {
// no more data
break;
}
outputStream.Write(buffer, 0, bytesRead);
}
}
}
}
}