I tried following this SO: Create zip file from byte[] as a dummy project and it looks like this:
using System.IO.Compression;
using System.IO;
using System.Net.Http;
using System;
namespace TestApp
{
internal class Program
{
static void Main(string[] args)
{
using var compressedFileStream = new MemoryStream();
using var zipArchive = new ZipArchive(compressedFileStream, ZipArchiveMode.Create);
//Create a zip entry for each attachment
var zipEntry = zipArchive.CreateEntry("test.txt");
var file = File.ReadAllBytes("test.txt");
//Get the stream of the attachment
using var originalFileStream = new MemoryStream(file);
using var zipEntryStream = zipEntry.Open();
//Copy the attachment stream to the zip entry stream
originalFileStream.CopyTo(zipEntryStream);
var toarraybaby = compressedFileStream.ToArray();
File.WriteAllBytes("hehe.zip", toarraybaby);
}
}
}
I get a .zip file as output and the file has a size. But when trying to open the file I get that its corrupt. What am I missing?