Added CreateEntryFromStream extension method

This commit is contained in:
Jaex 2020-08-11 20:24:44 +03:00
parent 47f862cf89
commit fba38a4005

View file

@ -159,5 +159,33 @@ public static void Compress(string archivePath, Dictionary<string, string> files
}
}
}
public static ZipArchiveEntry CreateEntryFromStream(this ZipArchive archive, Stream stream, string entryName, CompressionLevel compressionLevel)
{
if (archive == null)
{
throw new ArgumentNullException(nameof(archive));
}
if (stream == null)
{
throw new ArgumentNullException(nameof(stream));
}
if (entryName == null)
{
throw new ArgumentNullException(nameof(entryName));
}
ZipArchiveEntry entry = archive.CreateEntry(entryName, compressionLevel);
entry.LastWriteTime = DateTime.Now;
using (Stream entryStream = entry.Open())
{
stream.CopyTo(entryStream);
}
return entry;
}
}
}