From 1a4eec739177d9dd27b28d75a7c00d8d2fa24e0f Mon Sep 17 00:00:00 2001 From: carathorys Date: Wed, 11 Mar 2020 11:06:59 +0100 Subject: [PATCH] fix(saxophone): class visibility, parse refactor Saxophone now only made the on() and parse() functions to public; the parse now invokes `this.write` and then `this.end` --- src/Saxophone.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Saxophone.ts b/src/Saxophone.ts index 9362f23..48fff9c 100644 --- a/src/Saxophone.ts +++ b/src/Saxophone.ts @@ -15,9 +15,9 @@ const Buffer = require('buffer'); * */ export class Saxophone extends rStream.Writable { - _decoder: typeof stringDecoder.StringDecoder; - _tagStack: any[]; - _waiting: { token: any; data: any } | null = null; + private _decoder: typeof stringDecoder.StringDecoder; + private _tagStack: any[]; + private _waiting: { token: any; data: any } | null = null; /** * Create a new parser instance. @@ -47,7 +47,7 @@ export class Saxophone extends rStream.Writable { * @param {string} encoding Encoding of the string, or 'buffer'. * @param {function} callback */ - _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void { + private _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void { const data = encoding === 'buffer' ? this._decoder.write(chunk) : chunk; let error: any; try { @@ -64,7 +64,7 @@ export class Saxophone extends rStream.Writable { * * @param {function} callback */ - _final(callback: (error?: Error) => void): void { + private _final(callback: (error?: Error) => void): void { try { // Make sure all data has been extracted from the decoder this._parseChunk(this._decoder.end()); @@ -109,8 +109,9 @@ export class Saxophone extends rStream.Writable { * * @param input Input chunk. */ - public parse(input: Buffer | string): Saxophone { - this.end(input); + public parse(input: typeof rStream.Readable | Buffer | string): Saxophone { + this.write(input); + this.end(); return this; }