Skip to content

Commit a41e3a0

Browse files
committed
Clean up and formatting
1 parent 7a529c5 commit a41e3a0

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

src/Ramstack.FileSystem.Amazon/S3UploadStream.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ public override void Write(ReadOnlySpan<byte> buffer)
100100
try
101101
{
102102
_stream.Write(buffer);
103-
104103
if (_stream.Length >= MinPartSize)
105104
UploadPart();
106105
}
107-
catch (Exception exception)
106+
catch
108107
{
109108
Abort();
110-
ExceptionDispatchInfo.Throw(exception);
109+
throw;
111110
}
112111
}
113112

@@ -124,10 +123,10 @@ public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, Cancella
124123
if (_stream.Length >= MinPartSize)
125124
await UploadPartAsync(cancellationToken).ConfigureAwait(false);
126125
}
127-
catch (Exception exception)
126+
catch
128127
{
129128
await AbortAsync(cancellationToken).ConfigureAwait(false);
130-
ExceptionDispatchInfo.Throw(exception);
129+
throw;
131130
}
132131
}
133132

@@ -254,10 +253,10 @@ private async ValueTask UploadPartAsync(CancellationToken cancellationToken)
254253
_stream.Position = 0;
255254
_stream.SetLength(0);
256255
}
257-
catch (Exception exception)
256+
catch
258257
{
259258
await AbortAsync(cancellationToken).ConfigureAwait(false);
260-
ExceptionDispatchInfo.Throw(exception);
259+
throw;
261260
}
262261
}
263262
}

src/Ramstack.FileSystem.Google/GcsWriteStream.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Ramstack.FileSystem.Google;
44

55
/// <summary>
6-
/// Represents a temporary write-only stream for Google Cloud Storage operations, redirecting all write operations to a temporary file.
7-
/// Upon disposing or closing the stream, the data is transferred to the Azure Blob storage.
6+
/// Represents a temporary write-only stream that buffers data to a temporary file before uploading it to Google Cloud Storage.
7+
/// Data is committed to the storage bucket when the stream is disposed or closed.
88
/// </summary>
99
internal sealed class GcsWriteStream : Stream
1010
{
1111
private readonly GoogleFileSystem _fs;
1212
private readonly string _objectName;
13-
private readonly FileStream _stream = CreateTempFileStream();
13+
private readonly FileStream _stream;
1414
private bool _disposed;
1515

1616
/// <inheritdoc />
@@ -53,6 +53,16 @@ public GcsWriteStream(GoogleFileSystem fs, string objectName)
5353
{
5454
_fs = fs;
5555
_objectName = objectName;
56+
_stream = new FileStream(
57+
Path.Combine(
58+
Path.GetTempPath(),
59+
Path.GetRandomFileName()),
60+
FileMode.CreateNew,
61+
FileAccess.ReadWrite,
62+
FileShare.None,
63+
bufferSize: 4096,
64+
FileOptions.DeleteOnClose
65+
| FileOptions.Asynchronous);
5666
}
5767

5868
/// <inheritdoc />
@@ -84,7 +94,6 @@ public override void Write(ReadOnlySpan<byte> buffer)
8494
{
8595
_disposed = true;
8696
_stream.Close();
87-
8897
throw;
8998
}
9099
}
@@ -104,7 +113,6 @@ public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, Cancella
104113
{
105114
_disposed = true;
106115
_stream.Close();
107-
108116
throw;
109117
}
110118
}
@@ -176,15 +184,6 @@ await _fs.StorageClient
176184
}
177185
}
178186

179-
private static FileStream CreateTempFileStream()
180-
{
181-
const int BufferSize = 4096;
182-
const FileOptions Options = FileOptions.DeleteOnClose | FileOptions.Asynchronous;
183-
184-
var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
185-
return new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read, BufferSize, Options);
186-
}
187-
188187
[DoesNotReturn]
189188
private static void Error_NotSupported() =>
190189
throw new NotSupportedException();

0 commit comments

Comments
 (0)