private byte[] DecompressTopicData(byte[] input, HelpTopic topic, SerializationOptions options) { // The first two bytes indicates decompressed data size. if (input.Length < 2) { var e = new InvalidTopicDataEventArgs(topic, input, "Not enough bytes for DecodedLength field."); this.InvalidTopicData?.Invoke(this, e); return(null); } int decompressedLength = BitConverter.ToUInt16(input, 0); // The rest of the buffer is a huffman stream wrapping a // compression stream wrapping binary-encoded topic data. byte[] output; using (var memoryStream = new MemoryStream(input, 2, input.Length - 2)) using (var huffmanStream = new HuffmanStream(memoryStream, options.HuffmanTree)) using (var compressionStream = new CompressionStream(huffmanStream, options.Keywords)) using (var compressionReader = new BinaryReader(compressionStream)) { output = compressionReader.ReadBytes(decompressedLength); } if (output.Length != decompressedLength) { var e = new InvalidTopicDataEventArgs(topic, input, string.Format("Decompressed topic size mismatch: " + "expecting {0} bytes, got {1} bytes.", decompressedLength, output.Length)); this.InvalidTopicData?.Invoke(this, e); } return(output); }
private void OnInvalidTopicData(object sender, QuickHelp.Serialization.InvalidTopicDataEventArgs e) { this.deserializationErrors.Add(e); }