| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.IO; |
| | 7 | | using System.Text; |
| | 8 | | using Azure.Storage.Shared; |
| | 9 | |
|
| | 10 | | #pragma warning disable SA1402 // File may only contain a single type |
| | 11 | |
|
| | 12 | | namespace Azure.Storage.Files.Shares.Models |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// The properties and content returned from downloading a file |
| | 16 | | /// </summary> |
| | 17 | | public partial class ShareFileDownloadInfo : IDisposable, IDownloadedContent |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Internal flattened property representation |
| | 21 | | /// </summary> |
| | 22 | | internal FlattenedStorageFileProperties _flattened; |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// The number of bytes present in the response body. |
| | 26 | | /// </summary> |
| 2 | 27 | | public long ContentLength => _flattened.ContentLength; |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Content |
| | 31 | | /// </summary> |
| 57 | 32 | | public Stream Content => _flattened.Content; |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// The content type specified for the file. The default content type is 'application/octet-stream' |
| | 36 | | /// </summary> |
| 2 | 37 | | public string ContentType => _flattened.ContentType; |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// If the file has an MD5 hash and this operation is to read the full content, this response header is returned |
| | 41 | | /// </summary> |
| | 42 | | #pragma warning disable CA1819 // Properties should not return arrays |
| 0 | 43 | | public byte[] ContentHash => _flattened.ContentHash; |
| | 44 | | #pragma warning restore CA1819 // Properties should not return arrays |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Details returned when downloading a file |
| | 48 | | /// </summary> |
| 99 | 49 | | public ShareFileDownloadDetails Details { get; private set; } |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Creates a new StorageFileDownloadInfo backed by FlattenedStorageFileProperties |
| | 53 | | /// </summary> |
| | 54 | | /// <param name="flattened">The FlattenedStorageFileProperties returned with the request</param> |
| 61 | 55 | | internal ShareFileDownloadInfo(FlattenedStorageFileProperties flattened) |
| | 56 | | { |
| 61 | 57 | | _flattened = flattened; |
| 61 | 58 | | Details = new ShareFileDownloadDetails(flattened); |
| 61 | 59 | | } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Disposes the StorageFileDownloadInfo by calling Dispose on the underlying Content stream. |
| | 63 | | /// </summary> |
| | 64 | | public void Dispose() |
| | 65 | | { |
| 1 | 66 | | Content?.Dispose(); |
| 1 | 67 | | GC.SuppressFinalize(this); |
| 1 | 68 | | } |
| | 69 | | } |
| | 70 | | /// <summary> |
| | 71 | | /// FilesModelFactory provides utilities for mocking. |
| | 72 | | /// </summary> |
| | 73 | | public static partial class FilesModelFactory |
| | 74 | | { |
| | 75 | | /// <summary> |
| | 76 | | /// Creates a new StorageFileDownloadInfo instance for mocking. |
| | 77 | | /// </summary> |
| | 78 | | public static ShareFileDownloadInfo StorageFileDownloadInfo( |
| | 79 | | System.DateTimeOffset lastModified = default, |
| | 80 | | System.Collections.Generic.IEnumerable<string> contentLanguage = default, |
| | 81 | | string acceptRanges = default, |
| | 82 | | System.DateTimeOffset copyCompletionTime = default, |
| | 83 | | string copyStatusDescription = default, |
| | 84 | | string contentDisposition = default, |
| | 85 | | string copyProgress = default, |
| | 86 | | System.Uri copySource = default, |
| | 87 | | Azure.Storage.Files.Shares.Models.CopyStatus copyStatus = default, |
| | 88 | | byte[] fileContentHash = default, |
| | 89 | | bool isServerEncrypted = default, |
| | 90 | | string cacheControl = default, |
| | 91 | | string fileAttributes = default, |
| | 92 | | System.Collections.Generic.IEnumerable<string> contentEncoding = default, |
| | 93 | | System.DateTimeOffset fileCreationTime = default, |
| | 94 | | byte[] contentHash = default, |
| | 95 | | System.DateTimeOffset fileLastWriteTime = default, |
| | 96 | | ETag eTag = default, |
| | 97 | | System.DateTimeOffset fileChangeTime = default, |
| | 98 | | string contentRange = default, |
| | 99 | | string filePermissionKey = default, |
| | 100 | | string contentType = default, |
| | 101 | | string fileId = default, |
| | 102 | | long contentLength = default, |
| | 103 | | string fileParentId = default, |
| | 104 | | System.Collections.Generic.IDictionary<string, string> metadata = default, |
| | 105 | | System.IO.Stream content = default, |
| | 106 | | string copyId = default) |
| | 107 | | { |
| | 108 | | return new ShareFileDownloadInfo( |
| | 109 | | new FlattenedStorageFileProperties() |
| | 110 | | { |
| | 111 | | LastModified = lastModified, |
| | 112 | | ContentLanguage = contentLanguage, |
| | 113 | | AcceptRanges = acceptRanges, |
| | 114 | | CopyCompletionTime = copyCompletionTime, |
| | 115 | | CopyStatusDescription = copyStatusDescription, |
| | 116 | | ContentDisposition = contentDisposition, |
| | 117 | | CopyProgress = copyProgress, |
| | 118 | | CopySource = copySource, |
| | 119 | | CopyStatus = copyStatus, |
| | 120 | | FileContentHash = fileContentHash, |
| | 121 | | IsServerEncrypted = isServerEncrypted, |
| | 122 | | CacheControl = cacheControl, |
| | 123 | | FileAttributes = fileAttributes, |
| | 124 | | ContentEncoding = contentEncoding, |
| | 125 | | FileCreationTime = fileCreationTime, |
| | 126 | | ContentHash = contentHash, |
| | 127 | | FileLastWriteTime = fileLastWriteTime, |
| | 128 | | ETag = eTag, |
| | 129 | | FileChangeTime = fileChangeTime, |
| | 130 | | ContentRange = contentRange, |
| | 131 | | FilePermissionKey = filePermissionKey, |
| | 132 | | ContentType = contentType, |
| | 133 | | FileId = fileId, |
| | 134 | | ContentLength = contentLength, |
| | 135 | | FileParentId = fileParentId, |
| | 136 | | Metadata = metadata, |
| | 137 | | Content = content, |
| | 138 | | CopyId = copyId, |
| | 139 | | } |
| | 140 | | ); |
| | 141 | | } |
| | 142 | | } |
| | 143 | | } |