Fix a few thing with compose

This commit is contained in:
Lewis Diamond
2019-12-06 16:38:52 -05:00
parent ff2b652ddf
commit 4b806c4d4e
7 changed files with 1351 additions and 1826 deletions

View File

@@ -4,6 +4,7 @@ import { SerializationFormats } from "./baseDefinitions";
export function parse(
format: SerializationFormats = SerializationFormats.utf8,
emitError: boolean = true,
): Transform {
const decoder = new StringDecoder(format);
return new Transform({
@@ -13,9 +14,13 @@ export function parse(
try {
const asString = decoder.write(chunk);
// Using await causes parsing errors to be emitted
callback(undefined, await JSON.parse(asString));
callback(null, await JSON.parse(asString));
} catch (err) {
callback(err);
if (emitError) {
callback(err);
} else {
callback();
}
}
},
});