Always write to temp file if compressing after

This commit is contained in:
Matt Nadareski
2024-07-16 15:14:59 -04:00
parent 41d8b4297e
commit b9817c9af5
3 changed files with 11 additions and 5 deletions

View File

@@ -425,9 +425,9 @@ namespace SabreTools.DatTools
if (RebuildTorrentXz(datFile, datItem, file, outDir, outputFormat, isZip))
return true;
// If there is more than one dupe, write to a temporary file and use that stream instead
// Create a temp file if we're compressing the data after
string? tempFile = null;
if (dupes.Count > 1)
if (outputFormat != OutputFormat.Folder)
{
tempFile = Path.Combine(outDir, $"tmp{System.Guid.NewGuid()}");
Stream tempStream = System.IO.File.Open(tempFile, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

View File

@@ -328,7 +328,9 @@ namespace SabreTools.FileTypes.Archives
usableDate = dt;
// Copy the input stream to the output
if (inputStream.CanSeek)
inputStream.Seek(0, SeekOrigin.Begin);
tarFile.AddEntry(baseFile.Filename, inputStream, size: baseFile.Size ?? 0, modified: usableDate);
}
@@ -384,7 +386,9 @@ namespace SabreTools.FileTypes.Archives
if (index < 0)
{
// Copy the input file to the output
if (inputStream.CanSeek)
inputStream.Seek(0, SeekOrigin.Begin);
tarFile.AddEntry(baseFile.Filename, inputStream, size: baseFile.Size ?? 0, modified: usableDate);
}

View File

@@ -428,7 +428,9 @@ namespace SabreTools.FileTypes.Archives
// If the archive doesn't exist, create it and put the single file
if (!File.Exists(archiveFileName))
{
if (inputStream.CanSeek)
inputStream.Seek(0, SeekOrigin.Begin);
zipReturn = zipFile.ZipFileCreate(tempFile);
// Open the input file for reading