Как создать z z-файл gz из байтового массива, сгенерированного из gziptream
У меня есть основное приложение.net, в котором я создаю в памяти zip с тремя файлами и отправляю его в байтовом массиве в другое клиентское приложение. Сейчас я пытаюсь в своем клиентском приложении сохранить этот байтовый массив в ZIP-файл.gz. Мой код для создания архива
byte[] fileBytes = null;
using (MemoryStream memoryStream = new MemoryStream())
{
// create a zip
using (ZipArchive zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, true, Encoding.UTF8))
{
// iterate through the source files
foreach (var f in obj.CsvDictionary)
{
// add the item name to the zip
ZipArchiveEntry zipItem = zip.CreateEntry(f.Key);//f.key contains file name
// add the item bytes to the zip entry by opening the original file and copying the bytes
using (var originalFileMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(f.Value.ToString())))//f.value contains file contents
{
using (var entryStream = zipItem.Open())
{
originalFileMemoryStream.CopyTo(entryStream);
}
}
}
}
fileBytes = memoryStream.ToArray();
}
1 ответ
Решение
Это было так просто, как
File.WriteAllBytes(@"D:\Temp\Myfile.zip", myrequestarray);
https://www.codeproject.com/Questions/666195/Byte-Array-to-Zip-File