private EmbeddedSourceTextInfo?ResolveEmbeddedSource( DocumentHandle document, SourceTextInfo sourceTextInfo ) { byte[] bytes = ( from handle in PdbReader.GetCustomDebugInformation(document) let cdi = PdbReader.GetCustomDebugInformation(handle) where PdbReader.GetGuid(cdi.Kind) == EmbeddedSourceGuid select PdbReader.GetBlobBytes(cdi.Value) ).SingleOrDefault(); if (bytes is null) { return(null); } int uncompressedSize = BitConverter.ToInt32(bytes, 0); var stream = new MemoryStream(bytes, sizeof(int), bytes.Length - sizeof(int)); byte[]? compressedHash = null; if (uncompressedSize != 0) { using var algorithm = CryptographicHashProvider.TryGetAlgorithm(sourceTextInfo.HashAlgorithm) ?? throw new InvalidOperationException(); compressedHash = algorithm.ComputeHash(bytes); var decompressed = new MemoryStream(uncompressedSize); using (var deflater = new DeflateStream(stream, CompressionMode.Decompress)) { deflater.CopyTo(decompressed); } if (decompressed.Length != uncompressedSize) { throw new InvalidDataException(); } stream = decompressed; } using (stream) { // todo: IVT and EncodedStringText.Create? var embeddedText = SourceText.From( stream, encoding: sourceTextInfo.SourceTextEncoding, checksumAlgorithm: sourceTextInfo.HashAlgorithm, canBeEmbedded: true ); return(new EmbeddedSourceTextInfo( sourceTextInfo, embeddedText, compressedHash?.ToImmutableArray() ?? ImmutableArray <byte> .Empty )); } }
private (SourceText?embeddedText, byte[]? compressedHash) ResolveEmbeddedSource(DocumentHandle document, SourceHashAlgorithm hashAlgorithm, Encoding encoding) { byte[] bytes = (from handle in PdbReader.GetCustomDebugInformation(document) let cdi = PdbReader.GetCustomDebugInformation(handle) where PdbReader.GetGuid(cdi.Kind) == EmbeddedSourceGuid select PdbReader.GetBlobBytes(cdi.Value)).SingleOrDefault(); if (bytes == null) { return(default);