@@ -2,7 +2,7 @@ import * as RDF from "@rdfjs/types";
22// tslint:disable-next-line:no-var-requires
33const Parser = require ( 'jsonparse' ) ;
44import { ERROR_CODES , ErrorCoded , IDocumentLoader , JsonLdContext , Util as ContextUtil } from "jsonld-context-parser" ;
5- import { PassThrough , Transform } from "readable-stream" ;
5+ import { PassThrough , Transform , Readable } from "readable-stream" ;
66import { EntryHandlerArrayValue } from "./entryhandler/EntryHandlerArrayValue" ;
77import { EntryHandlerContainer } from "./entryhandler/EntryHandlerContainer" ;
88import { EntryHandlerInvalidFallback } from "./entryhandler/EntryHandlerInvalidFallback" ;
@@ -157,12 +157,18 @@ export class JsonLdParser extends Transform implements RDF.Sink<EventEmitter, RD
157157 * @return {RDF.Stream } A quad stream.
158158 */
159159 public import ( stream : EventEmitter ) : RDF . Stream {
160- const output = new PassThrough ( { readableObjectMode : true } ) ;
161- stream . on ( 'error' , ( error ) => parsed . emit ( 'error' , error ) ) ;
162- stream . on ( 'data' , ( data ) => output . push ( data ) ) ;
163- stream . on ( 'end' , ( ) => output . push ( null ) ) ;
164- const parsed = output . pipe ( new JsonLdParser ( this . options ) ) ;
165- return parsed ;
160+ if ( 'pipe' in stream ) {
161+ stream . on ( 'error' , ( error ) => parsed . emit ( 'error' , error ) ) ;
162+ const parsed = ( < Readable > stream ) . pipe ( new JsonLdParser ( this . options ) ) ;
163+ return parsed ;
164+ } else {
165+ const output = new PassThrough ( { readableObjectMode : true } ) ;
166+ stream . on ( 'error' , ( error ) => parsed . emit ( 'error' , error ) ) ;
167+ stream . on ( 'data' , ( data ) => output . push ( data ) ) ;
168+ stream . on ( 'end' , ( ) => output . push ( null ) ) ;
169+ const parsed = output . pipe ( new JsonLdParser ( this . options ) ) ;
170+ return parsed ;
171+ }
166172 }
167173
168174 public _transform ( chunk : any , encoding : string , callback : ( error ?: Error | null , data ?: any ) => void ) : void {
0 commit comments