diff --git a/types/msgpack-lite/index.d.ts b/types/msgpack-lite/index.d.ts index 2148e03624..cb01aab422 100644 --- a/types/msgpack-lite/index.d.ts +++ b/types/msgpack-lite/index.d.ts @@ -5,6 +5,7 @@ /// import * as stream from 'stream'; +import { EventEmitter } from 'events'; /** * encode from JS Object to MessagePack @@ -84,7 +85,9 @@ export interface Encoder { end(chunk: any): void; } -export interface Decoder { +export function Decoder(options?: DecoderOptions): Decoder; + +export interface Decoder extends EventEmitter { bufferish: any; offset: number; fetch(): void; diff --git a/types/msgpack-lite/msgpack-lite-tests.ts b/types/msgpack-lite/msgpack-lite-tests.ts index 781063e6d4..975e7e0c7f 100644 --- a/types/msgpack-lite/msgpack-lite-tests.ts +++ b/types/msgpack-lite/msgpack-lite-tests.ts @@ -84,3 +84,18 @@ function customExtensionTypes() { return new MyVector(array[0], array[1]); // return Object deserialized } } + +// https://github.com/kawanet/msgpack-lite#benchmarks +// (this is not well documented, but in the test there is an example usage.) +function standaloneDecoder() { + const decoder = msgpack.Decoder(); + const object = { test: "Object" }; + const encoded = msgpack.encode(object); + decoder.on('data', (obj) => { + if (object.test !== obj.test) { + throw Error(); + } + }); + + decoder.push(encoded); +}