MiloszKrajewski / K4os.Compression.LZ4

LZ4/LH4HC compression for .NET Standard 1.6/2.0 (formerly known as lz4net)
MIT License
675 stars 77 forks source link

why Length return 7 #82

Closed xibaoning closed 1 year ago

xibaoning commented 1 year ago

using var ms = new MemoryStream(); using (var zip = LZ4Stream.Encode(ms)) { var buffer2 = new byte[1024 * 64]; for (int i = 0; i < buffer2.Length; i++) buffer2[i] = (byte)i; zip.Write(buffer2, 0, 1011); zip.Flush(); int contnetlength = (int)ms.Length; // the contnetlength = 7 }

MiloszKrajewski commented 1 year ago

move Length inspection AFTER compression stream is disposed or closed. 7 bytes is the header, which get's written when stream starts. Flush is not saving data, as it would need to close frame, and then it could not be appended to anymore. Trade-off.