// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc { /// /// Represents an that when executed will /// write a binary file to the response. /// public class FileContentResult : FileResult { private byte[] _fileContents; /// /// Creates a new instance with /// the provided and the /// provided . /// /// The bytes that represent the file contents. /// The Content-Type header of the response. public FileContentResult([NotNull] byte[] fileContents, [NotNull] string contentType) : this(fileContents, new MediaTypeHeaderValue(contentType)) { } /// /// Creates a new instance with /// the provided and the /// provided . /// /// The bytes that represent the file contents. /// The Content-Type header of the response. public FileContentResult([NotNull] byte[] fileContents, [NotNull] MediaTypeHeaderValue contentType) : base(contentType) { FileContents = fileContents; } /// /// Gets or sets the file contents. /// public byte[] FileContents { get { return _fileContents; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _fileContents = value; } } /// protected override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation) { return response.Body.WriteAsync(FileContents, 0, FileContents.Length, cancellation); } } }