本文整理汇总了TypeScript中msgpack-lite.createDecodeStream函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createDecodeStream函数的具体用法?TypeScript createDecodeStream怎么用?TypeScript createDecodeStream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createDecodeStream函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: readingFromStream
// https://github.com/kawanet/msgpack-lite#reading-from-messagepack-stream
function readingFromStream() {
const fs = require("fs");
const readStream = fs.createReadStream("test.msp");
const decodeStream = msgpack.createDecodeStream();
// show multiple objects decoded from stream
readStream.pipe(decodeStream).on("data", console.warn);
}
示例2:
const wrap = <R, W>(socket: Socket): [TinyReader<R>, TinyWriter<W>] => {
const writer = wrapWriter<W>(socket, msgpack.encode)
const readStream = msgpack.createDecodeStream()
socket.pipe(readStream)
const reader = wrapReader<R>(readStream)
return [reader, writer]
}
示例3: serve
export const serveToSocket = <Val>(store: I.Store<Val>, socket: Socket) => {
const writer = msgpack.createEncodeStream()
writer.pipe(socket)
socket.on('end', () => {
// This isn't passed through for some reason.
writer.end()
})
const reader = msgpack.createDecodeStream()
socket.pipe(reader)
serve(wrapReader(reader), wrapWriter(writer), store)
}