private void ReadFromBuffer(ref ReadOnlySequence <byte> buffer, ParsingData parsingData) { while (TryReadLine(ref buffer, out ReadOnlySequence <byte> sequence)) { IParsedLine parsedLine = ProcessSequence( sequence, ref parsingData.CurrentOffset, parsingData.ParseMode); if (parsedLine == null) { continue; } if (parsedLine.ParseMode == ParseMode.Regular && parsedLine is ObjectDataParsedLine objectDataParsedLine) { parsingData.PdfObjects.Add(objectDataParsedLine.ObjectData); } if (parsedLine.ParseMode == ParseMode.InsideXref && parsedLine is XRefTableHeaderParsedLine xRefTableHeaderParsedLine) { parsingData.CurrentXRefTableFirstObjectNumber = xRefTableHeaderParsedLine.FirstObjectNumber; parsingData.CurrentXRefTableSize = xRefTableHeaderParsedLine.TableSize; parsingData.CurrentXRefTableObjectNumberIndex = 0; } if (parsedLine.ParseMode == ParseMode.InsideXref && parsedLine is ObjectDataParsedLine xrefObjectDataParsedLine) { parsingData.XRefObjects.Add( new ObjectData( parsingData.CurrentXRefTableObjectNumberIndex + parsingData.CurrentXRefTableFirstObjectNumber, xrefObjectDataParsedLine.ObjectData.ObjectGeneration, xrefObjectDataParsedLine.ObjectData.ObjectOffset)); parsingData.CurrentXRefTableObjectNumberIndex++; } parsingData.ParseMode = parsedLine.ParseMode; } }
public async Task <ValidationResult> Validate(string file) { using (FileStream stream = File.OpenRead(file)) { PipeReader reader = PipeReader.Create(stream); ParsingData parsingData = new ParsingData(); bool isReadComplete = false; while (!isReadComplete) { ReadResult read = await reader.ReadAsync(); ReadOnlySequence <byte> buffer = read.Buffer; ReadFromBuffer(ref buffer, parsingData); reader.AdvanceTo(buffer.Start, buffer.End); isReadComplete = read.IsCompleted; } return(ValidatePdfObjectsToXrefObjects(parsingData.PdfObjects, parsingData.XRefObjects)); } }