mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Added CreateEntryFromStream extension method
This commit is contained in:
parent
47f862cf89
commit
fba38a4005
1 changed files with 28 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue