Skip to content

Commit

Permalink
Decompress in chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryQuan committed Oct 1, 2023
1 parent 06b9b72 commit c3aed81
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,22 @@ private static void Decrypt(BinaryReader binaryReader, Stream targetStream)
}
}

private static readonly object _fileLock = new object();
private static readonly object _decompressLock = new object();
private static void Decompress(Stream compressedStream, Stream decompressedStream)
{
lock (_fileLock)
// DeflateStream doesn't strip the header so we strip it manually.
compressedStream.Seek(2, SeekOrigin.Begin);
byte[] buffer = new byte[4096];
int bytesRead;
lock (_decompressLock)
{
// DeflateStream doesn't strip the header so we strip it manually.
compressedStream.Seek(2, SeekOrigin.Begin);
using DeflateStream deflateStream = new(compressedStream, CompressionMode.Decompress);
deflateStream.CopyTo(decompressedStream);
decompressedStream.Seek(0, SeekOrigin.Begin);
while ((bytesRead = deflateStream.Read(buffer, 0, buffer.Length)) > 0)
{
decompressedStream.Write(buffer, 0, bytesRead);
}
}
decompressedStream.Seek(0, SeekOrigin.Begin);
}
}

Expand Down

0 comments on commit c3aed81

Please sign in to comment.