Optimized some buffer copying in GZip stuff.

This commit is contained in:
That_One_Nerd 2023-03-30 10:28:56 -04:00
parent 8f7c2775d4
commit 33130bc5f8
2 changed files with 3 additions and 31 deletions

View File

@ -32,27 +32,14 @@ public static class CompressionModule
reader = new(absSource, FileMode.Open);
GZipStream gzip = new(writer, level);
LoadingBarStart();
int bufferSize = Mathf.Clamp((int)reader.Length / Console.BufferWidth, 1024 * 1024, 128 * 1024 * 1024);
byte[] buffer = new byte[bufferSize];
for (long i = 0; i < reader.Length; i += bufferSize)
{
int size = reader.Read(buffer, 0, bufferSize);
gzip.Write(buffer, 0, size);
gzip.Flush();
LoadingBarSet((float)i / reader.Length, ConsoleColor.DarkGreen);
}
LoadingBarEnd();
reader.CopyTo(gzip);
gzip.Close();
reader.Close();
writer.Close();
Console.CursorLeft = 0;
Console.CursorTop -= (message.Length / Console.BufferWidth) + 2;
Console.CursorTop -= (message.Length / Console.BufferWidth) + 1;
Write(new string(' ', message.Length), newLine: false);
}
else if (Directory.Exists(source)) throw new("The GZip format can only compress 1 file.");

View File

@ -29,21 +29,7 @@ public static class ExtractionModule
reader = new(absSource, FileMode.Open);
GZipStream gzip = new(reader, CompressionMode.Decompress);
LoadingBarStart();
int bufferSize = Mathf.Clamp((int)reader.Length / Console.BufferWidth, 1024 * 1024, 128 * 1024 * 1024);
byte[] buffer = new byte[bufferSize];
int i = 0;
int size;
while ((size = gzip.Read(buffer, i, bufferSize)) > 0)
{
writer.Write(buffer, 0, size);
writer.Flush();
LoadingBarSet((float)i / reader.Length, ConsoleColor.DarkGreen);
}
LoadingBarEnd();
gzip.CopyTo(writer);
gzip.Close();
reader.Close();
@ -51,7 +37,6 @@ public static class ExtractionModule
Console.CursorLeft = 0;
Console.CursorTop -= (message.Length / Console.BufferWidth) + 1;
if (Console.CursorTop >= Console.BufferHeight - 3) Console.CursorTop--;
Write(new string(' ', message.Length), newLine: false);
}