Skip to content

Commit 472e277

Browse files
committed
Style tweaks
1 parent 5d2d6f3 commit 472e277

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/BaGet.AWS/Extensions/ServiceCollectionExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Amazon;
1+
using Amazon;
22
using Amazon.Runtime;
33
using Amazon.S3;
44
using BaGet.AWS.Configuration;
@@ -15,7 +15,7 @@ public static IServiceCollection AddS3StorageService(this IServiceCollection ser
1515
{
1616
var options = provider.GetRequiredService<IOptions<S3StorageOptions>>().Value;
1717

18-
AmazonS3Config config = new AmazonS3Config
18+
var config = new AmazonS3Config
1919
{
2020
RegionEndpoint = RegionEndpoint.GetBySystemName(options.Region)
2121
};

src/BaGet.AWS/S3StorageService.cs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Threading;
44
using System.Threading.Tasks;
@@ -34,12 +34,14 @@ private string PrepareKey(string path)
3434

3535
public async Task<Stream> GetAsync(string path, CancellationToken cancellationToken = default)
3636
{
37-
MemoryStream stream = new MemoryStream();
37+
var stream = new MemoryStream();
3838

3939
try
4040
{
41-
using (GetObjectResponse res = await _client.GetObjectAsync(_bucket, PrepareKey(path), cancellationToken))
42-
await res.ResponseStream.CopyToAsync(stream);
41+
using (var request = await _client.GetObjectAsync(_bucket, PrepareKey(path), cancellationToken))
42+
{
43+
await request.ResponseStream.CopyToAsync(stream);
44+
}
4345

4446
stream.Seek(0, SeekOrigin.Begin);
4547
}
@@ -56,31 +58,31 @@ public async Task<Stream> GetAsync(string path, CancellationToken cancellationTo
5658

5759
public Task<Uri> GetDownloadUriAsync(string path, CancellationToken cancellationToken = default)
5860
{
59-
string res = _client.GetPreSignedURL(new GetPreSignedUrlRequest
61+
var url = _client.GetPreSignedURL(new GetPreSignedUrlRequest
6062
{
6163
BucketName = _bucket,
6264
Key = PrepareKey(path)
6365
});
6466

65-
return Task.FromResult(new Uri(res));
67+
return Task.FromResult(new Uri(url));
6668
}
6769

6870
public async Task<PutResult> PutAsync(string path, Stream content, string contentType, CancellationToken cancellationToken = default)
6971
{
7072
// TODO: Uploads should be idempotent. This should fail if and only if the blob
7173
// already exists but has different content.
7274

73-
using (MemoryStream ms = new MemoryStream())
75+
using (var seekableContent = new MemoryStream())
7476
{
75-
await content.CopyToAsync(ms, 4096, cancellationToken);
77+
await content.CopyToAsync(seekableContent, 4096, cancellationToken);
7678

77-
ms.Seek(0, SeekOrigin.Begin);
79+
seekableContent.Seek(0, SeekOrigin.Begin);
7880

7981
await _client.PutObjectAsync(new PutObjectRequest
8082
{
8183
BucketName = _bucket,
8284
Key = PrepareKey(path),
83-
InputStream = ms,
85+
InputStream = seekableContent,
8486
ContentType = contentType,
8587
AutoResetStreamPosition = false,
8688
AutoCloseStream = false

src/BaGet.Core/Services/FileStorageService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Threading;
44
using System.Threading.Tasks;
@@ -104,7 +104,7 @@ private string GetFullPath(string path)
104104
throw new ArgumentException("Path is required", nameof(path));
105105
}
106106

107-
string fullPath = Path.GetFullPath(Path.Combine(_storePath, path));
107+
var fullPath = Path.GetFullPath(Path.Combine(_storePath, path));
108108

109109
// Verify path is under the _storePath.
110110
if (!fullPath.StartsWith(_storePath, StringComparison.Ordinal) ||

0 commit comments

Comments
 (0)