/// <summary> /// Writes the byte-array content to the response. /// <para> /// This supports range requests (<see cref="StatusCodes.Status206PartialContent"/> or /// <see cref="StatusCodes.Status416RangeNotSatisfiable"/> if the range is not satisfiable). /// </para> /// <para> /// This API is an alias for <see cref="File(byte[], string, string?, bool, DateTimeOffset?, EntityTagHeaderValue?)"/>.</para> /// </summary> /// <param name="contents">The file contents.</param> /// <param name="contentType">The Content-Type of the file.</param> /// <param name="fileDownloadName">The suggested file name.</param> /// <param name="enableRangeProcessing">Set to <c>true</c> to enable range requests processing.</param> /// <param name="lastModified">The <see cref="DateTimeOffset"/> of when the file was last modified.</param> /// <param name="entityTag">The <see cref="EntityTagHeaderValue"/> associated with the file.</param> /// <returns>The created <see cref="IResult"/> for the response.</returns> public static IResult Bytes( byte[] contents, string?contentType = null, string?fileDownloadName = null, bool enableRangeProcessing = false, DateTimeOffset?lastModified = null, EntityTagHeaderValue?entityTag = null) => TypedResults.Bytes(contents, contentType, fileDownloadName, enableRangeProcessing, lastModified, entityTag);
/// <summary> /// Writes the byte-array content to the response. /// <para> /// This supports range requests (<see cref="StatusCodes.Status206PartialContent"/> or /// <see cref="StatusCodes.Status416RangeNotSatisfiable"/> if the range is not satisfiable). /// </para> /// </summary> /// <param name="contents">The file contents.</param> /// <param name="contentType">The Content-Type of the file.</param> /// <param name="fileDownloadName">The suggested file name.</param> /// <param name="enableRangeProcessing">Set to <c>true</c> to enable range requests processing.</param> /// <param name="lastModified">The <see cref="DateTimeOffset"/> of when the file was last modified.</param> /// <param name="entityTag">The <see cref="EntityTagHeaderValue"/> associated with the file.</param> /// <returns>The created <see cref="IResult"/> for the response.</returns> #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public static IResult Bytes( #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters ReadOnlyMemory <byte> contents, string?contentType = null, string?fileDownloadName = null, bool enableRangeProcessing = false, DateTimeOffset?lastModified = null, EntityTagHeaderValue?entityTag = null) => TypedResults.Bytes(contents, contentType, fileDownloadName, enableRangeProcessing, lastModified, entityTag);
public void BytesOrFile_ResultHasCorrectValues(int bytesOrFile, string contentType, string fileDownloadName, bool enableRangeProcessing, DateTimeOffset lastModified, EntityTagHeaderValue entityTag) { // Arrange var contents = new byte[0]; // Act var result = bytesOrFile switch { 0 => TypedResults.Bytes(contents, contentType, fileDownloadName, enableRangeProcessing, lastModified, entityTag), _ => TypedResults.File(contents, contentType, fileDownloadName, enableRangeProcessing, lastModified, entityTag) }; // Assert Assert.Equal(contents, result.FileContents); Assert.Equal(contentType ?? "application/octet-stream", result.ContentType); Assert.Equal(fileDownloadName, result.FileDownloadName); Assert.Equal(enableRangeProcessing, result.EnableRangeProcessing); Assert.Equal(lastModified, result.LastModified); Assert.Equal(entityTag, result.EntityTag); }
public void Bytes_WithNullContents_ThrowsArgNullException() { Assert.Throws <ArgumentNullException>("contents", () => TypedResults.Bytes(null)); }