wechaty-puppet-service
Version:
Puppet Service for Wechaty
56 lines • 1.77 kB
JavaScript
import { Transform } from 'stronger-typed-streams';
import { PassThrough } from 'stream';
/**
* Wrap FileBoxChunk
* @deprecated Will be removed after Dec 31, 2022
*/
const encoder = (PbConstructor) => new Transform({
objectMode: true,
transform: (chunk, _, callback) => {
const message = new PbConstructor();
message.setFileBoxChunk(chunk);
callback(null, message);
},
});
/**
* @deprecated Will be removed after Dec 31, 2022
*/
function packFileBoxChunkToPb(PbConstructor) {
return (stream) => {
const outStream = new PassThrough({ objectMode: true });
const encodedStream = stream.pipe(encoder(PbConstructor));
stream.on('error', e => outStream.emit('error', e));
encodedStream.on('error', e => outStream.emit('error', e));
encodedStream.pipe(outStream);
return outStream;
};
}
/**
* Unwrap FileBoxChunk
* @deprecated Will be removed after Dec 31, 2022
*/
const decoder = () => new Transform({
objectMode: true,
transform: (chunk, _, callback) => {
const fileBoxChunk = chunk.getFileBoxChunk();
if (!fileBoxChunk) {
callback(new Error('No FileBoxChunk'));
}
else {
callback(null, fileBoxChunk);
}
},
});
/**
* @deprecated Will be removed after Dec 31, 2022
*/
function unpackFileBoxChunkFromPb(stream) {
const outStream = new PassThrough({ objectMode: true });
const decodedStream = stream.pipe(decoder());
stream.on('error', e => outStream.emit('error', e));
decodedStream.on('error', e => outStream.emit('error', e));
decodedStream.pipe(outStream);
return outStream;
}
export { packFileBoxChunkToPb, unpackFileBoxChunkFromPb, };
//# sourceMappingURL=chunk-pb.js.map