UNPKG

wechaty-puppet-service

Version:
60 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unpackFileBoxChunkFromPb = exports.packFileBoxChunkToPb = void 0; const stronger_typed_streams_1 = require("stronger-typed-streams"); const stream_1 = require("stream"); /** * Wrap FileBoxChunk * @deprecated Will be removed after Dec 31, 2022 */ const encoder = (PbConstructor) => new stronger_typed_streams_1.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 stream_1.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; }; } exports.packFileBoxChunkToPb = packFileBoxChunkToPb; /** * Unwrap FileBoxChunk * @deprecated Will be removed after Dec 31, 2022 */ const decoder = () => new stronger_typed_streams_1.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 stream_1.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; } exports.unpackFileBoxChunkFromPb = unpackFileBoxChunkFromPb; //# sourceMappingURL=chunk-pb.js.map