Optimized some buffer copying in GZip stuff.
This commit is contained in:
parent
8f7c2775d4
commit
33130bc5f8
@ -32,27 +32,14 @@ public static class CompressionModule
|
|||||||
reader = new(absSource, FileMode.Open);
|
reader = new(absSource, FileMode.Open);
|
||||||
GZipStream gzip = new(writer, level);
|
GZipStream gzip = new(writer, level);
|
||||||
|
|
||||||
LoadingBarStart();
|
reader.CopyTo(gzip);
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
gzip.Close();
|
gzip.Close();
|
||||||
reader.Close();
|
reader.Close();
|
||||||
writer.Close();
|
writer.Close();
|
||||||
|
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
Console.CursorTop -= (message.Length / Console.BufferWidth) + 2;
|
Console.CursorTop -= (message.Length / Console.BufferWidth) + 1;
|
||||||
Write(new string(' ', message.Length), newLine: false);
|
Write(new string(' ', message.Length), newLine: false);
|
||||||
}
|
}
|
||||||
else if (Directory.Exists(source)) throw new("The GZip format can only compress 1 file.");
|
else if (Directory.Exists(source)) throw new("The GZip format can only compress 1 file.");
|
||||||
|
|||||||
@ -29,21 +29,7 @@ public static class ExtractionModule
|
|||||||
reader = new(absSource, FileMode.Open);
|
reader = new(absSource, FileMode.Open);
|
||||||
GZipStream gzip = new(reader, CompressionMode.Decompress);
|
GZipStream gzip = new(reader, CompressionMode.Decompress);
|
||||||
|
|
||||||
LoadingBarStart();
|
gzip.CopyTo(writer);
|
||||||
|
|
||||||
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.Close();
|
gzip.Close();
|
||||||
reader.Close();
|
reader.Close();
|
||||||
@ -51,7 +37,6 @@ public static class ExtractionModule
|
|||||||
|
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
Console.CursorTop -= (message.Length / Console.BufferWidth) + 1;
|
Console.CursorTop -= (message.Length / Console.BufferWidth) + 1;
|
||||||
if (Console.CursorTop >= Console.BufferHeight - 3) Console.CursorTop--;
|
|
||||||
Write(new string(' ', message.Length), newLine: false);
|
Write(new string(' ', message.Length), newLine: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user