wechaty-grpc
Version:
gRPC for Wechaty
32 lines • 780 B
JavaScript
/**
* A stream transformer that encodes chunks into protobufs (and vice versa)
*/
import { Transform, } from 'stronger-typed-streams';
/**
* Wrap Chunk
*/
const chunkEncoder = (PbConstructor) => new Transform({
objectMode: true,
transform: (chunk, _, callback) => {
const pb = new PbConstructor();
pb.setChunk(chunk);
callback(null, pb);
},
});
/**
* Unwrap Chunk
*/
const chunkDecoder = () => new Transform({
objectMode: true,
transform: (pb, _, callback) => {
const chunk = pb.getChunk();
if (chunk) {
callback(null, chunk);
}
else {
callback(new Error('NOCHUNK'));
}
},
});
export { chunkEncoder, chunkDecoder, };
//# sourceMappingURL=chunk-transformer.js.map