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))
|
||||
{
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageId>tsZip.NS</PackageId>
|
||||
<PackageTags>netstandard2.0, libreria</PackageTags>
|
||||
<Version>1.0.0</Version>
|
||||
<Version>1.0.1</Version>
|
||||
<Authors>Manuel</Authors>
|
||||
<Company>Tecnosis S.A</Company>
|
||||
<Description>Utilidades de compresión</Description>
|
||||
<PackageReleaseNotes>
|
||||
- 2026-05-25 Correcciones en crear ficheros
|
||||
- 2026-05-14 Versión 5 Regeneración completa de la clase con copilot
|
||||
</PackageReleaseNotes>
|
||||
<!--<PackageReadmeFile>README.md</PackageReadmeFile>-->
|
||||
|
||||
Reference in New Issue
Block a user