mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: metadata file error in FileResourceStore
* Fix: metadata file error in FileResourceStore * fix: ensure full test coverage * add stream piping function in util * Fix typing in util function * Add requested changes * add suggested changes * add suggested change Co-authored-by: freyavs <freyavanspeybroeck@outlook.com>
This commit is contained in:
committed by
GitHub
parent
7fae3203d5
commit
c808dfeff0
@@ -6,6 +6,7 @@ import { NamedNode, Quad } from 'rdf-js';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { TEXT_TURTLE } from '../util/ContentTypes';
|
||||
import { LDP, RDF, STAT, TERMS, XML } from './Prefixes';
|
||||
import { pipeStreamsAndErrors } from './Util';
|
||||
|
||||
export const TYPE_PREDICATE = DataFactory.namedNode(`${RDF}type`);
|
||||
export const MODIFIED_PREDICATE = DataFactory.namedNode(`${TERMS}modified`);
|
||||
@@ -64,13 +65,13 @@ export class MetadataController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to convert an array of quads into a Readable object.
|
||||
* Helper function for serializing an array of quads, with as result a Readable object.
|
||||
* @param quads - The array of quads.
|
||||
*
|
||||
* @returns The Readable object.
|
||||
*/
|
||||
public generateReadableFromQuads(quads: Quad[]): Readable {
|
||||
return streamifyArray(quads).pipe(new StreamWriter({ format: TEXT_TURTLE }));
|
||||
public serializeQuads(quads: Quad[]): Readable {
|
||||
return pipeStreamsAndErrors(streamifyArray(quads), new StreamWriter({ format: TEXT_TURTLE }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +80,7 @@ export class MetadataController {
|
||||
*
|
||||
* @returns A promise containing the array of quads.
|
||||
*/
|
||||
public async generateQuadsFromReadable(readable: Readable): Promise<Quad[]> {
|
||||
return arrayifyStream(readable.pipe(new StreamParser({ format: TEXT_TURTLE })));
|
||||
public async parseQuads(readable: Readable): Promise<Quad[]> {
|
||||
return await arrayifyStream(pipeStreamsAndErrors(readable, new StreamParser({ format: TEXT_TURTLE })));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Readable } from 'stream';
|
||||
import { Readable, Writable } from 'stream';
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import { UnsupportedHttpError } from './errors/UnsupportedHttpError';
|
||||
|
||||
/**
|
||||
* Makes sure the input path has exactly 1 slash at the end.
|
||||
@@ -51,3 +52,17 @@ export const matchingMediaType = (mediaA: string, mediaB: string): boolean => {
|
||||
}
|
||||
return subTypeA === subTypeB;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pipes one stream into another.
|
||||
* Makes sure an error of the first stream gets passed to the second.
|
||||
* @param readable - Initial readable stream.
|
||||
* @param destination - The destination for writing data.
|
||||
*
|
||||
* @returns The destination stream.
|
||||
*/
|
||||
export const pipeStreamsAndErrors = <T extends Writable>(readable: Readable, destination: T): T => {
|
||||
readable.pipe(destination);
|
||||
readable.on('error', (error): boolean => destination.emit('error', new UnsupportedHttpError(error.message)));
|
||||
return destination;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user