1
- using System ;
1
+ using System ;
2
2
using System . IO ;
3
3
using System . Threading ;
4
4
using System . Threading . Tasks ;
@@ -34,12 +34,14 @@ private string PrepareKey(string path)
34
34
35
35
public async Task < Stream > GetAsync ( string path , CancellationToken cancellationToken = default )
36
36
{
37
- MemoryStream stream = new MemoryStream ( ) ;
37
+ var stream = new MemoryStream ( ) ;
38
38
39
39
try
40
40
{
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
+ }
43
45
44
46
stream . Seek ( 0 , SeekOrigin . Begin ) ;
45
47
}
@@ -56,31 +58,31 @@ public async Task<Stream> GetAsync(string path, CancellationToken cancellationTo
56
58
57
59
public Task < Uri > GetDownloadUriAsync ( string path , CancellationToken cancellationToken = default )
58
60
{
59
- string res = _client . GetPreSignedURL ( new GetPreSignedUrlRequest
61
+ var url = _client . GetPreSignedURL ( new GetPreSignedUrlRequest
60
62
{
61
63
BucketName = _bucket ,
62
64
Key = PrepareKey ( path )
63
65
} ) ;
64
66
65
- return Task . FromResult ( new Uri ( res ) ) ;
67
+ return Task . FromResult ( new Uri ( url ) ) ;
66
68
}
67
69
68
70
public async Task < PutResult > PutAsync ( string path , Stream content , string contentType , CancellationToken cancellationToken = default )
69
71
{
70
72
// TODO: Uploads should be idempotent. This should fail if and only if the blob
71
73
// already exists but has different content.
72
74
73
- using ( MemoryStream ms = new MemoryStream ( ) )
75
+ using ( var seekableContent = new MemoryStream ( ) )
74
76
{
75
- await content . CopyToAsync ( ms , 4096 , cancellationToken ) ;
77
+ await content . CopyToAsync ( seekableContent , 4096 , cancellationToken ) ;
76
78
77
- ms . Seek ( 0 , SeekOrigin . Begin ) ;
79
+ seekableContent . Seek ( 0 , SeekOrigin . Begin ) ;
78
80
79
81
await _client . PutObjectAsync ( new PutObjectRequest
80
82
{
81
83
BucketName = _bucket ,
82
84
Key = PrepareKey ( path ) ,
83
- InputStream = ms ,
85
+ InputStream = seekableContent ,
84
86
ContentType = contentType ,
85
87
AutoResetStreamPosition = false ,
86
88
AutoCloseStream = false
0 commit comments