public IEnumerable ReadRecordsFromDecompressedStream()

in src/StructuredLogger/BinaryLogger/BinLogReader.cs [214:298]


        public IEnumerable<Record> ReadRecordsFromDecompressedStream(Stream decompressedStream)
        {
            var wrapper = new WrapperStream(decompressedStream);

            var binaryReader = new BinaryReader(wrapper);

            int fileFormatVersion = binaryReader.ReadInt32();

            EnsureFileFormatVersionKnown(fileFormatVersion);

            long lengthOfBlobsAddedLastTime = 0;

            List<Record> blobs = new List<Record>();

            using var reader = new BuildEventArgsReader(binaryReader, fileFormatVersion);

            // forward the events from the reader to the subscribers of this class
            reader.OnBlobRead += OnBlobRead;

            long start = 0;

            reader.OnBlobRead += (kind, blob) =>
            {
                start = wrapper.Position;

                var record = new Record
                {
                    Bytes = blob,
                    Args = null,
                    Start = start - blob.Length, // TODO: check if this is accurate
                    Length = blob.Length
                };

                blobs.Add(record);
                lengthOfBlobsAddedLastTime += blob.Length;
            };

            reader.OnStringRead += text =>
            {
                long length = wrapper.Position - start;

                // re-read the current position as we're just about to start reading
                // the actual BuildEventArgs record
                start = wrapper.Position;

                OnStringRead?.Invoke(text, length);
            };

            reader.OnNameValueListRead += list =>
            {
                long length = wrapper.Position - start;
                start = wrapper.Position;
                OnNameValueListRead?.Invoke(list, length);
            };

            while (true)
            {
                BuildEventArgs instance = null;

                start = wrapper.Position;

                instance = reader.Read();
                if (instance == null)
                {
                    break;
                }

                var record = new Record
                {
                    Bytes = null, // probably can reconstruct this from the Args if necessary
                    Args = instance,
                    Start = start,
                    Length = wrapper.Position - start
                };

                yield return record;

                lengthOfBlobsAddedLastTime = 0;
            }

            foreach (var blob in blobs)
            {
                yield return blob;
            }
        }