import { base64ToAscii } from '../../parsing/binary'; export class FirmwareClerk { resolve: Function; reject: Function; stringBuffer: string; constructor(resolve, reject) { this.resolve = resolve; this.reject = reject; this.stringBuffer = ''; } appendString(aString) { this.stringBuffer += base64ToAscii(aString); try { const result = JSON.parse(this.stringBuffer); if (!result.Version) { throw Error('Version not found in probe info'); } this.resolve(result.Version); } catch (err) { if (err instanceof SyntaxError) { // If it's a JSON parsing error, do nothing and wait for more bytes } else { console.error(err); this.reject('Se produjo un error al recuperar el firmware'); } } } }