|
4 | 4 |
|
5 | 5 | namespace SabreTools.IO.Compression.MSZIP |
6 | 6 | { |
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"/> |
8 | 8 | public class Decompressor |
9 | 9 | { |
10 | 10 | /// <summary> |
11 | 11 | /// Last uncompressed block data |
12 | 12 | /// </summary> |
13 | 13 | private byte[]? _history = null; |
14 | 14 |
|
| 15 | + /// <summary> |
| 16 | + /// Required output buffer size (32KiB) |
| 17 | + /// </summary> |
| 18 | + private const int _bufferSize = 0x8000; |
| 19 | + |
15 | 20 | #region Constructors |
16 | 21 |
|
17 | 22 | /// <summary> |
@@ -51,20 +56,20 @@ public bool CopyTo(Stream source, Stream dest) |
51 | 56 | if (header.Signature != 0x4B43) |
52 | 57 | throw new InvalidDataException(nameof(source)); |
53 | 58 |
|
54 | | - byte[] buffer = new byte[32 * 1024]; |
| 59 | + byte[] buffer = new byte[_bufferSize]; |
55 | 60 | var blockStream = new Deflate.DeflateStream(source, Deflate.CompressionMode.Decompress, leaveOpen: true); |
56 | 61 | if (_history != null) |
57 | 62 | blockStream.SetDictionary(_history, check: false); |
58 | 63 |
|
59 | | - int read = blockStream.Read(buffer, 0, buffer.Length); |
| 64 | + int read = blockStream.Read(buffer, 0, _bufferSize); |
60 | 65 | if (read > 0) |
61 | 66 | { |
62 | 67 | // Write to output |
63 | | - dest.Write(buffer, 0, read); |
| 68 | + dest.Write(buffer, 0, _bufferSize); |
64 | 69 |
|
65 | 70 | // 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); |
68 | 73 | } |
69 | 74 |
|
70 | 75 | // Flush and return |
|
0 commit comments