diff --git a/src/Squirrel/BinaryPatchUtility.cs b/src/Squirrel/BinaryPatchUtility.cs index b1eda7ec8..d25c0bc04 100644 --- a/src/Squirrel/BinaryPatchUtility.cs +++ b/src/Squirrel/BinaryPatchUtility.cs @@ -230,10 +230,13 @@ 0 32 Header WriteInt64(controlEndPosition - startPosition - c_headerSize, header, 8); // write compressed diff data - using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None)) - using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress)) + if (dblen > 0) { - bz2Stream.Write(db, 0, dblen); + using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None)) + using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress)) + { + bz2Stream.Write(db, 0, dblen); + } } // compute size of compressed diff data @@ -241,10 +244,13 @@ 0 32 Header WriteInt64(diffEndPosition - controlEndPosition, header, 16); // write compressed extra data - using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None)) - using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress)) + if (eblen > 0) { - bz2Stream.Write(eb, 0, eblen); + using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None)) + using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress)) + { + bz2Stream.Write(eb, 0, eblen); + } } // seek to the beginning, write the header, then seek back to end