Skip to content

Commit

Permalink
Assume newline after stream to be in line with spec
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolaVerbeeck committed Sep 6, 2023
1 parent 89235ce commit 92cb3fb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/src/parser/pdf_object_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class PDFObjectParser {
}

Future<PDFStreamObject?> _parseStream(PDFDictionary dictionary) async {
final line = await ReaderHelper.readWordTrimmed(_buffer);
final line = await ReaderHelper.readLine(_buffer);
if ('tartxref' == line) return null;
assert('tream' == line);

Expand Down
6 changes: 0 additions & 6 deletions lib/src/utils/reader_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ abstract class ReaderHelper {
}
word.writeCharCode(await tokenStream.consumeToken());
}
// Trim the end
try {
await skipUntilFirstNonWhitespace(tokenStream);
} on EOFException {
// Ignore
}
return word.toString();
}

Expand Down
7 changes: 4 additions & 3 deletions test/parser/pdf_stream_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ void streamParserTests() {
group('Stream parser tests', () {
test('Test empty stream', () async {
final stream =
await createParserFromString('<</Length 0>>stream endstream').parse();
await createParserFromString('<</Length 0>>stream\nendstream')
.parse();
expect(stream, isA<PDFStreamObject>());

stream as PDFStreamObject;
Expand All @@ -23,7 +24,7 @@ void streamParserTests() {
.thenAnswer((invocation) async => const PDFIndirectObject(
objectId: 1, generationNumber: 0, object: PDFNumber(0)));
final stream = await createParserFromString(
'<</Length 1 0 R>>stream endstream',
'<</Length 1 0 R>>stream\nendstream',
mockParser,
).parse();
expect(stream, isA<PDFStreamObject>());
Expand All @@ -38,7 +39,7 @@ void streamParserTests() {
});
test('Test stream with data', () async {
final stream =
await createParserFromString('<</Length 3>>stream abcendstream')
await createParserFromString('<</Length 3>>stream\nabcendstream')
.parse();
expect(stream, isA<PDFStreamObject>());

Expand Down

0 comments on commit 92cb3fb

Please sign in to comment.