Skip to content

Commit

Permalink
feat: add typed readable
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Jun 17, 2020
1 parent aaf3f8e commit e0d74fd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ldp/representation/BinaryRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Representation } from './Representation';
import { TypedReadable } from '../../util/TypedReadable';

/**
* A representation containing binary data.
*/
export interface BinaryRepresentation extends Representation {
dataType: 'binary';
data: TypedReadable<Buffer>;
}
3 changes: 3 additions & 0 deletions src/ldp/representation/QuadRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Quad } from 'rdf-js';
import { Representation } from './Representation';
import { TypedReadable } from '../../util/TypedReadable';

/**
* A representation containing quads as data.
*/
export interface QuadRepresentation extends Representation {
dataType: 'quad';
data: TypedReadable<Quad>;
}
33 changes: 33 additions & 0 deletions src/util/TypedReadable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Readable } from 'stream';

/**
* Interface providing typed functions for Readable streams.
*/
export interface TypedReadable<T> extends Readable {
read(size?: number): any;
unshift(chunk: any, encoding?: BufferEncoding): void;
push(chunk: any, encoding?: BufferEncoding): boolean;

addListener(event: 'data', listener: (chunk: T) => void): this;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;

emit(event: 'data', chunk: T): boolean;
emit(event: string | symbol, ...args: any[]): boolean;

on(event: 'data', listener: (chunk: T) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;

once(event: 'data', listener: (chunk: T) => void): TypedReadable<T>;
once(event: string | symbol, listener: (...args: any[]) => void): this;

prependListener(event: 'data', listener: (chunk: T) => void): TypedReadable<T>;
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;

prependOnceListener(event: 'data', listener: (chunk: T) => void): TypedReadable<T>;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;

removeListener(event: 'data', listener: (chunk: T) => void): TypedReadable<T>;
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;

[Symbol.asyncIterator](): AsyncIterableIterator<T>;
}

0 comments on commit e0d74fd

Please sign in to comment.