I have the following method which gets a memory stream and compresses it using ZipArchive:
public async Task<MemoryStream> CompressStreamAsync(MemoryStream content, string fileName)
{
var memoryStream = new MemoryStream();
memoryStream.Seek(0, SeekOrigin.Begin);
using var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true);
var zipArchiveEntry = zipArchive.CreateEntry(fileName);
using var streamWriter = new StreamWriter(zipArchiveEntry.Open());
var charArrayContent = Encoding.UTF8.GetString(content.GetBuffer())
.ToCharArray();
await streamWriter.WriteAsync(charArrayContent, 0, charArrayContent.Length);
return memoryStream;
}
When extracting the archive content, the archived file's size is bigger then it originally was and I noticed white space at the end of the file, which wasn't in the original file. Any ideas why this might happen ?
Best regards.