diff --git a/CHANGELIST.md b/CHANGELIST.md index fb33c667..87996879 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -40,6 +40,7 @@ - Pre-compress skeleton files with Zstd - Fix broken file count tests - Pre-compress state files with Zstd +- Use block-based reading instead of CopyTo ### 3.4.2 (2025-09-30) diff --git a/MPF.Processors/Redumper.cs b/MPF.Processors/Redumper.cs index 1583e092..af10666b 100644 --- a/MPF.Processors/Redumper.cs +++ b/MPF.Processors/Redumper.cs @@ -676,15 +676,26 @@ namespace MPF.Processors if (!File.Exists(file)) return false; - // Create and write the output try { + // Prepare the input and output streams using var ifs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using var ofs = File.Open($"{file}.zst", FileMode.Create, FileAccess.Write, FileShare.None); - using var zst = new ZStandardStream(ofs, CompressionMode.Compress, compressionLevel: 19, leaveOpen: true); - ifs.CopyTo(zst); - zst.Flush(); + + // Compress and write in blocks + int read = 0; + do + { + byte[] buffer = new byte[3 * 1024 * 1024]; + + read = ifs.Read(buffer, 0, buffer.Length); + if (read == 0) + break; + + zst.Write(buffer, 0, read); + zst.Flush(); + } while (read > 0); } catch {