Im using the ZipDotNet library for C#.
I created a byte array with random data like this:
public static byte[] GetRandomBytes(int Length)
{
byte[] data = new byte[Length];
Random random = new Random();
random.NextBytes(data);
return data;
}
Now I want to zip those bytes to a MemoryStream and return the MemoryStream as byte array too.
public static byte[] zipFileToStream(byte[] file)
{
using (MemoryStream memStream = new MemoryStream())
{
using (ZipFile zip = new ZipFile())
{
zip.AddEntry("file.txt", file);
zip.Save(memStream);
}
return memStream.ToArray();
}
}
When I print out the returning byte array, then there are always the same bytes in?
Can anyone help me with my issue?
Setting the MemoryStrream Position to 0 solved the issue.