[英]Handling Nodejs streams with AngularJS
I am using nodejs streams to fetch data from my level database (using leveldb). 我正在使用nodejs流从我的关卡数据库中获取数据(使用leveldb)。 Here is a snippet of the code I use: 这是我使用的代码片段:
app.get('/my/route', function (req, res, next) {
leveldb.createValueStream(options)
.pipe(map.obj(function (hash) {
level.get(somekeys, function (err, item) {
return item
})
}))
.pipe(res)
})
So far, I have been using the list-stream
module to get the data on the client side. 到目前为止,我一直在使用list-stream
模块在客户端获取数据。
Now I'd like to retrieve the information on the client side as a stream. 现在,我想以流的形式检索客户端上的信息。 I've read this post ( http://www.kdelemme.com/2014/04/24/use-socket-io-to-stream-tweets-between-nodejs-and-angularjs/ ) on how to do it using socket.io but I don't want to use socket.io 我已经阅读了有关如何使用它的文章( http://www.kdelemme.com/2014/04/24/use-socket-io-to-stream-tweets-between-nodejs-and-angularjs/ ) socket.io,但我不想使用socket.io
Is there any simple way to do it? 有什么简单的方法吗?
The createValueStream
basically is a read stream, then you can listen to the event eg., data
, end
: https://github.com/substack/node-levelup#createValueStream createValueStream
基本上是一个读取流,然后您可以侦听事件,例如data
, end
: https : //github.com/substack/node-levelup#createValueStream
Just need to listen to end
event to finish the stream. 只需要听end
事件来完成流。
app.get('/my/route', function (req, res, next) {
leveldb.createValueStream(options)
.pipe(map.obj(function (hash) {
level.get(somekeys, function (err, item) {
return item
})
}))
.pipe(res)
.on('end', res.end)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.