2026-05-25 Correcciones en crear ficheros
This commit is contained in:
26
Zip.cs
26
Zip.cs
@@ -144,29 +144,33 @@ public static class Zip
|
||||
|
||||
public static byte[] ComprimirArchivos(Dictionary<string, byte[]> archivos)
|
||||
{
|
||||
string tempZip = Path.GetTempFileName();
|
||||
// Crear un nombre de archivo temporal que NO exista
|
||||
string tempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".zip");
|
||||
|
||||
using (var zip = ZipFile.Open(tempZip, ZipArchiveMode.Create))
|
||||
using (ZipArchive zip = ZipFile.Open(tempFileName, ZipArchiveMode.Create))
|
||||
{
|
||||
foreach (var kv in archivos)
|
||||
foreach (var archivo in archivos)
|
||||
{
|
||||
var entry = zip.CreateEntry(kv.Key, CompressionLevel.Optimal);
|
||||
using (var entryStream = entry.Open())
|
||||
var entry = zip.CreateEntry(archivo.Key, CompressionLevel.Optimal);
|
||||
using (Stream stream = entry.Open())
|
||||
{
|
||||
byte[] data = kv.Value;
|
||||
entryStream.Write(data, 0, data.Length);
|
||||
byte[] data = archivo.Value;
|
||||
stream.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
byte[] resultado = File.ReadAllBytes(tempZip);
|
||||
try { File.Delete(tempZip); } catch { }
|
||||
return resultado;
|
||||
byte[] result = File.ReadAllBytes(tempFileName);
|
||||
|
||||
try { File.Delete(tempFileName); } catch { }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static byte[] ComprimirArchivos(Dictionary<string, Stream> archivos)
|
||||
{
|
||||
string tempZip = Path.GetTempFileName();
|
||||
string tempZip = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".zip");
|
||||
|
||||
using (var zip = ZipFile.Open(tempZip, ZipArchiveMode.Create))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user