mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Use declarations style for functions.
This commit is contained in:
@@ -13,7 +13,9 @@ const logger = getLoggerFor('StreamUtil');
|
||||
*
|
||||
* @returns The joined string.
|
||||
*/
|
||||
export const readableToString = async(stream: Readable): Promise<string> => (await arrayifyStream(stream)).join('');
|
||||
export async function readableToString(stream: Readable): Promise<string> {
|
||||
return (await arrayifyStream(stream)).join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Pipes one stream into another and emits errors of the first stream with the second.
|
||||
@@ -25,8 +27,8 @@ export const readableToString = async(stream: Readable): Promise<string> => (awa
|
||||
*
|
||||
* @returns The destination stream.
|
||||
*/
|
||||
export const pipeSafely = <T extends Writable>(readable: NodeJS.ReadableStream, destination: T,
|
||||
mapError?: (error: Error) => Error): Guarded<T> => {
|
||||
export function pipeSafely<T extends Writable>(readable: NodeJS.ReadableStream, destination: T,
|
||||
mapError?: (error: Error) => Error): Guarded<T> {
|
||||
// Not using `stream.pipeline` since the result there only emits an error event if the last stream has the error
|
||||
readable.pipe(destination);
|
||||
readable.on('error', (error): void => {
|
||||
@@ -39,12 +41,13 @@ export const pipeSafely = <T extends Writable>(readable: NodeJS.ReadableStream,
|
||||
destination.destroy(mapError ? mapError(error) : error);
|
||||
});
|
||||
return guardStream(destination);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an iterable to a stream and applies an error guard so that it is {@link Guarded}.
|
||||
* @param iterable - Data to stream.
|
||||
* @param options - Options to pass to the Readable constructor. See {@link Readable.from}.
|
||||
*/
|
||||
export const guardedStreamFrom = (iterable: Iterable<any>, options?: ReadableOptions): Guarded<Readable> =>
|
||||
guardStream(Readable.from(iterable, options));
|
||||
export function guardedStreamFrom(iterable: Iterable<any>, options?: ReadableOptions): Guarded<Readable> {
|
||||
return guardStream(Readable.from(iterable, options));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user