Skip to content

Commit 4dc1378

Browse files
committed
Make MS-ZIP more consistent
1 parent ae87869 commit 4dc1378

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

SabreTools.IO/Compression/MSZIP/Decompressor.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44

55
namespace SabreTools.IO.Compression.MSZIP
66
{
7-
/// <see href="https://msopenspecs.azureedge.net/files/MS-MCI/%5bMS-MCI%5d.pdf"/>
7+
/// <see href="https://officeprotocoldoc.z19.web.core.windows.net/files/MS-MCI/%5bMS-MCI%5d.pdf"/>
88
public class Decompressor
99
{
1010
/// <summary>
1111
/// Last uncompressed block data
1212
/// </summary>
1313
private byte[]? _history = null;
1414

15+
/// <summary>
16+
/// Required output buffer size (32KiB)
17+
/// </summary>
18+
private const int _bufferSize = 0x8000;
19+
1520
#region Constructors
1621

1722
/// <summary>
@@ -51,20 +56,20 @@ public bool CopyTo(Stream source, Stream dest)
5156
if (header.Signature != 0x4B43)
5257
throw new InvalidDataException(nameof(source));
5358

54-
byte[] buffer = new byte[32 * 1024];
59+
byte[] buffer = new byte[_bufferSize];
5560
var blockStream = new Deflate.DeflateStream(source, Deflate.CompressionMode.Decompress, leaveOpen: true);
5661
if (_history != null)
5762
blockStream.SetDictionary(_history, check: false);
5863

59-
int read = blockStream.Read(buffer, 0, buffer.Length);
64+
int read = blockStream.Read(buffer, 0, _bufferSize);
6065
if (read > 0)
6166
{
6267
// Write to output
63-
dest.Write(buffer, 0, read);
68+
dest.Write(buffer, 0, _bufferSize);
6469

6570
// Save the history for rollover
66-
_history = new byte[read];
67-
Array.Copy(buffer, _history, read);
71+
_history = new byte[_bufferSize];
72+
Array.Copy(buffer, _history, _bufferSize);
6873
}
6974

7075
// Flush and return

0 commit comments

Comments
 (0)