Skip to content

Commit

Permalink
Support .trig extensions without content type
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jan 29, 2025
1 parent e19f2b7 commit a94a70b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export class Util {
if (baseIRI.endsWith('.ttl')) {
return data.pipe(new GeneralizedN3StreamParser({ baseIRI, format: 'text/turtle', }));
}
if (baseIRI.endsWith('.trig')) {
return data.pipe(new GeneralizedN3StreamParser({ baseIRI, format: 'application/trig', }));
}

throw new Error(`Could not parse the RDF serialization ${contentType} on ${baseIRI}`);
}
Expand Down
9 changes: 9 additions & 0 deletions test/Util-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ describe('Util', () => {
]);
});

it('should workaround an unknown content type with explicit url extension for trig', async () => {
expect(await arrayifyStream(Util.parseRdfRaw('unknown', 'http://example.org/apples.trig',
streamifyString('<a> <b> <c>.'))))
.toEqualRdfQuadArray([
DF.quad(DF.namedNode('http://example.org/a'), DF.namedNode('http://example.org/b'),
DF.namedNode('http://example.org/c')),
]);
});

it('should parse application/x-turtle streams', async () => {
expect(await arrayifyStream(Util.parseRdfRaw('application/x-turtle', 'http://example.org/',
streamifyString('<a> <b> <c>.'))))
Expand Down

0 comments on commit a94a70b

Please sign in to comment.