1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
18 public class FileStreamResult : FileResult {
\r
20 // default buffer size as defined in BufferedStream type
\r
21 private const int _bufferSize = 0x1000;
\r
23 public FileStreamResult(Stream fileStream, string contentType)
\r
24 : base(contentType) {
\r
25 if (fileStream == null) {
\r
26 throw new ArgumentNullException("fileStream");
\r
29 FileStream = fileStream;
\r
32 public Stream FileStream {
\r
37 protected override void WriteFile(HttpResponseBase response) {
\r
38 // grab chunks of data and write to the output stream
\r
39 Stream outputStream = response.OutputStream;
\r
40 using (FileStream) {
\r
41 byte[] buffer = new byte[_bufferSize];
\r
44 int bytesRead = FileStream.Read(buffer, 0, _bufferSize);
\r
45 if (bytesRead == 0) {
\r
50 outputStream.Write(buffer, 0, bytesRead);
\r