mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
23 lines
906 B
TypeScript
23 lines
906 B
TypeScript
import type { Readable } from 'stream';
|
|
import arrayifyStream from 'arrayify-stream';
|
|
import type { ParserOptions } from 'n3';
|
|
import { StreamParser, StreamWriter } from 'n3';
|
|
import type { Quad } from 'rdf-js';
|
|
import type { Guarded } from './GuardedStream';
|
|
import { guardedStreamFrom, pipeSafely } from './StreamUtil';
|
|
|
|
export function serializeQuads(quads: Quad[], contentType?: string): Guarded<Readable> {
|
|
return pipeSafely(guardedStreamFrom(quads), new StreamWriter({ format: contentType }));
|
|
}
|
|
|
|
/**
|
|
* Helper function to convert a Readable into an array of quads.
|
|
* @param readable - The readable object.
|
|
* @param options - Options for the parser.
|
|
*
|
|
* @returns A promise containing the array of quads.
|
|
*/
|
|
export async function parseQuads(readable: Guarded<Readable>, options: ParserOptions = {}): Promise<Quad[]> {
|
|
return arrayifyStream(pipeSafely(readable, new StreamParser(options)));
|
|
}
|