Gate more seeks

This commit is contained in:
Matt Nadareski
2024-07-17 14:46:14 -04:00
parent 5fecdad7af
commit 11fa1544f1
6 changed files with 58 additions and 42 deletions

View File

@@ -130,10 +130,10 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir)
{
// Try to extract a stream using the given information
(Stream? ms, string? realEntry) = GetEntryStream(entryName);
(Stream? stream, string? realEntry) = GetEntryStream(entryName);
// If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null)
if (stream != null && realEntry != null)
{
realEntry = Path.Combine(outDir, realEntry);
@@ -146,21 +146,23 @@ namespace SabreTools.FileTypes.Archives
FileStream fs = File.Create(realEntry);
if (fs != null)
{
ms.Seek(0, SeekOrigin.Begin);
if (stream.CanSeek)
stream.Seek(0, SeekOrigin.Begin);
byte[] zbuffer = new byte[_bufferSize];
int zlen;
while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0)
while ((zlen = stream.Read(zbuffer, 0, _bufferSize)) > 0)
{
fs.Write(zbuffer, 0, zlen);
fs.Flush();
}
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
}
else
{
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
realEntry = null;
}

View File

@@ -96,10 +96,10 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir)
{
// Try to extract a stream using the given information
(Stream? ms, string? realEntry) = GetEntryStream(entryName);
(Stream? stream, string? realEntry) = GetEntryStream(entryName);
// If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null)
if (stream != null && realEntry != null)
{
realEntry = Path.Combine(outDir, realEntry);
@@ -110,21 +110,23 @@ namespace SabreTools.FileTypes.Archives
FileStream fs = File.Create(realEntry);
if (fs != null)
{
ms.Seek(0, SeekOrigin.Begin);
if (stream.CanSeek)
stream.Seek(0, SeekOrigin.Begin);
byte[] zbuffer = new byte[_bufferSize];
int zlen;
while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0)
while ((zlen = stream.Read(zbuffer, 0, _bufferSize)) > 0)
{
fs.Write(zbuffer, 0, zlen);
fs.Flush();
}
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
}
else
{
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
realEntry = null;
}

View File

@@ -183,10 +183,10 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir)
{
// Try to extract a stream using the given information
(Stream? ms, string? realEntry) = GetEntryStream(entryName);
(Stream? stream, string? realEntry) = GetEntryStream(entryName);
// If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null)
if (stream != null && realEntry != null)
{
realEntry = Path.Combine(outDir, realEntry);
@@ -197,21 +197,23 @@ namespace SabreTools.FileTypes.Archives
FileStream fs = File.Create(realEntry);
if (fs != null)
{
ms.Seek(0, SeekOrigin.Begin);
if (stream.CanSeek)
stream.Seek(0, SeekOrigin.Begin);
byte[] zbuffer = new byte[_bufferSize];
int zlen;
while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0)
while ((zlen = stream.Read(zbuffer, 0, _bufferSize)) > 0)
{
fs.Write(zbuffer, 0, zlen);
fs.Flush();
}
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
}
else
{
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
realEntry = null;
}
@@ -445,6 +447,7 @@ namespace SabreTools.FileTypes.Archives
return success;
// Seek to the beginning of the stream
if (inputStream.CanSeek)
inputStream.Seek(0, SeekOrigin.Begin);
// Get the output archive name from the first rebuild rom
@@ -465,7 +468,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

View File

@@ -97,10 +97,10 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir)
{
// Try to extract a stream using the given information
(Stream? ms, string? realEntry) = GetEntryStream(entryName);
(Stream? stream, string? realEntry) = GetEntryStream(entryName);
// If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null)
if (stream != null && realEntry != null)
{
realEntry = Path.Combine(outDir, realEntry);
@@ -111,21 +111,23 @@ namespace SabreTools.FileTypes.Archives
FileStream fs = File.Create(realEntry);
if (fs != null)
{
ms.Seek(0, SeekOrigin.Begin);
if (stream.CanSeek)
stream.Seek(0, SeekOrigin.Begin);
byte[] zbuffer = new byte[_bufferSize];
int zlen;
while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0)
while ((zlen = stream.Read(zbuffer, 0, _bufferSize)) > 0)
{
fs.Write(zbuffer, 0, zlen);
fs.Flush();
}
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
}
else
{
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
realEntry = null;
}

View File

@@ -114,10 +114,10 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir)
{
// Try to extract a stream using the given information
(Stream? ms, string? realEntry) = GetEntryStream(entryName);
(Stream? stream, string? realEntry) = GetEntryStream(entryName);
// If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null)
if (stream != null && realEntry != null)
{
realEntry = Path.Combine(outDir, realEntry);
@@ -128,21 +128,23 @@ namespace SabreTools.FileTypes.Archives
FileStream fs = File.Create(realEntry);
if (fs != null)
{
ms.Seek(0, SeekOrigin.Begin);
if (stream.CanSeek)
stream.Seek(0, SeekOrigin.Begin);
byte[] zbuffer = new byte[_bufferSize];
int zlen;
while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0)
while ((zlen = stream.Read(zbuffer, 0, _bufferSize)) > 0)
{
fs.Write(zbuffer, 0, zlen);
fs.Flush();
}
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
}
else
{
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
realEntry = null;
}

View File

@@ -158,10 +158,10 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir)
{
// Try to extract a stream using the given information
(Stream? ms, string? realEntry) = GetEntryStream(entryName);
(Stream? stream, string? realEntry) = GetEntryStream(entryName);
// If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null)
if (stream != null && realEntry != null)
{
realEntry = Path.Combine(outDir, realEntry);
@@ -172,21 +172,23 @@ namespace SabreTools.FileTypes.Archives
FileStream fs = File.Create(realEntry);
if (fs != null)
{
ms.Seek(0, SeekOrigin.Begin);
if (stream.CanSeek)
stream.Seek(0, SeekOrigin.Begin);
byte[] zbuffer = new byte[_bufferSize];
int zlen;
while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0)
while ((zlen = stream.Read(zbuffer, 0, _bufferSize)) > 0)
{
fs.Write(zbuffer, 0, zlen);
fs.Flush();
}
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
}
else
{
ms?.Dispose();
stream?.Dispose();
fs?.Dispose();
realEntry = null;
}
@@ -408,6 +410,7 @@ namespace SabreTools.FileTypes.Archives
return success;
// Seek to the beginning of the stream
if (inputStream.CanSeek)
inputStream.Seek(0, SeekOrigin.Begin);
// Get the output archive name from the first rebuild rom