Fix ZipToDirectory closing the input streams

This commit is contained in:
Dominion
2023-06-11 14:34:50 -04:00
parent d6615ee5f6
commit cc6833ae1b
2 changed files with 10 additions and 2 deletions
@@ -292,7 +292,15 @@ namespace Tgstation.Server.Host.IO
if (zipFile == null)
throw new ArgumentNullException(nameof(zipFile));
using var archive = new ZipArchive(zipFile, ZipArchiveMode.Read);
#if NET7_0_OR_GREATER
#warning Check if zip file seeking has been addressesed. See https://github.com/tgstation/tgstation-server/issues/1531
#endif
// ZipArchive does a synchronous copy on unseekable streams we want to avoid
if (!zipFile.CanSeek)
throw new ArgumentException("Stream does not support seeking!", nameof(zipFile));
using var archive = new ZipArchive(zipFile, ZipArchiveMode.Read, true);
archive.ExtractToDirectory(path);
},
cancellationToken,
+1 -1
View File
@@ -198,7 +198,7 @@ namespace Tgstation.Server.Host.IO
/// Extract a set of <paramref name="zipFile"/> to a given <paramref name="path"/>.
/// </summary>
/// <param name="path">The path to unzip to.</param>
/// <param name="zipFile">The <see cref="Stream"/> of the <see cref="global::System.IO.Compression.ZipArchive"/>.</param>
/// <param name="zipFile">The <see cref="Stream"/> of the <see cref="global::System.IO.Compression.ZipArchive"/>. Must have <see cref="Stream.CanSeek"/> set to <see langword="true"/>. Will be read completely and left open. <see cref="Stream.Position"/> will be indeterminate.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task ZipToDirectory(string path, Stream zipFile, CancellationToken cancellationToken);