Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko committed Sep 2, 2024
1 parent a8f9d7e commit 27d63df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Snowflake.Data/Core/FileTransfer/EncryptionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static byte[] encryptFileKey(byte[] masterKey, byte[] unencryptedFileKey
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;

using (MemoryStream cipherStream = new MemoryStream())
MemoryStream cipherStream = new MemoryStream();
using (var encryptor = aes.CreateEncryptor())
using (CryptoStream cryptoStream = new CryptoStream(cipherStream, encryptor, CryptoStreamMode.Write))
{
Expand Down Expand Up @@ -238,7 +238,7 @@ private static byte[] decryptFileKey(byte[] masterKey, byte[] unencryptedFileKey
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;

using (MemoryStream cipherStream = new MemoryStream())
MemoryStream cipherStream = new MemoryStream();
using (var decryptor = aes.CreateDecryptor())
using (CryptoStream cryptoStream = new CryptoStream(cipherStream, decryptor, CryptoStreamMode.Write))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal static void DownloadOneFile(SFFileMetadata fileMetadata)
}

// Create stream object for reader and writer
using (Stream stream = new MemoryStream(File.ReadAllBytes(realSrcFilePath)))
Stream stream = new MemoryStream(File.ReadAllBytes(realSrcFilePath));
using (var fileStream = File.Create(output))
{
// Write file
Expand Down
47 changes: 20 additions & 27 deletions Snowflake.Data/Core/SFBindUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,36 +75,29 @@ public void Upload(Dictionary<string, BindingDTO> bindings)

StringBuilder sBuffer = new StringBuilder();
MemoryStream ms = new MemoryStream();
try
using (StreamWriter tw = new StreamWriter(ms))
{
using (StreamWriter tw = new StreamWriter(ms))

for (int i = startIndex; i < rowNum; i++)
{
sBuffer.Append(dataRows[i]);
}

for (int i = startIndex; i < rowNum; i++)
{
sBuffer.Append(dataRows[i]);
}

tw.Write(sBuffer.ToString());
tw.Flush();

try
{
string fileName = (++fileCount).ToString();
UploadStream(ref ms, fileName);
startIndex = rowNum;
curBytes = 0;
}
catch (IOException e)
{
// failure using stream put
throw new Exception("file stream upload error." + e.ToString());
}
tw.Write(sBuffer.ToString());
tw.Flush();

try
{
string fileName = (++fileCount).ToString();
UploadStream(ref ms, fileName);
startIndex = rowNum;
curBytes = 0;
}
catch (IOException e)
{

Check warning on line 97 in Snowflake.Data/Core/SFBindUploader.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/SFBindUploader.cs#L96-L97

Added lines #L96 - L97 were not covered by tests
// failure using stream put
throw new Exception("file stream upload error." + e.ToString());

Check warning on line 99 in Snowflake.Data/Core/SFBindUploader.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/SFBindUploader.cs#L99

Added line #L99 was not covered by tests
}
}
finally
{
ms.Dispose();
}
}
}
Expand Down Expand Up @@ -132,7 +125,7 @@ internal async Task UploadAsync(Dictionary<string, BindingDTO> bindings, Cancell
}

StringBuilder sBuffer = new StringBuilder();
using (MemoryStream ms = new MemoryStream())
MemoryStream ms = new MemoryStream();
using (StreamWriter tw = new StreamWriter(ms))
{
for (int i = startIndex; i < rowNum; i++)
Expand Down

0 comments on commit 27d63df

Please sign in to comment.