Created
March 5, 2019 16:59
-
-
Save unter/3aa0b0c35c8fe3fc29ae54725c168f20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void MemoryStreamTest() | |
{ | |
string localFilePath = @"c:\tmp"; | |
try | |
{ | |
using (MemoryStream memoryStream = new MemoryStream()) | |
{ | |
for (int i = 0; i< 256;i++) | |
{ | |
string tempFilePath = Path.Combine(localFilePath, $"file{i}"); | |
CreateRandomTempFile(tempFilePath, 8); | |
using (FileStream fs = new FileStream(tempFilePath, FileMode.Open)) | |
{ | |
fs.CopyTo(memoryStream); | |
} | |
File.Delete(tempFilePath); | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine($"Exception in MemoryStreamTest: {ex.Message}"); | |
Console.ReadLine(); | |
} | |
} | |
private static void CreateRandomTempFile(string fileName, long lengthInMb) | |
{ | |
// https://stackoverflow.com/questions/4432178/creating-a-random-file-in-c-sharp | |
byte[] data = new byte[lengthInMb * 1024 * 1024]; | |
Random rng = new Random(); | |
rng.NextBytes(data); | |
File.WriteAllBytes(fileName, data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for you blogpost!