Tag: 式传输

为什么快速的默认error handling程序捕获从可读stream发射时的错误?

我使用命令行express stream_test安装了样板快速应用程序。 我用下面的/routes/index.jsreplace了默认的/routes/index.js : var express = require('express'); var router = express.Router(); var ReadFile = require('./readFile.js'); /* GET home page. */ router.get('/', function(req, res, next) { var readFile = ReadFile(); readFile .on('data', function(data) { res.write(data); }) .on('end', function() { res.end(); }) .on('error', function(err) { console.log(err); }); }); module.exports = router; readFile.js只是fs.createReadStream一个简单包装: var Readable = require('stream').Readable; […]

在Node.js中stream式传输video的一部分

我正在使用模块( BinaryJS )将存储在服务器中的video传递给浏览器(客户端)。 我的目标是不播放整个video,而是一部分。 我试过的是 //Creating the client var client = new BinaryClient('ws://localhost:9000/binary-endpoint') //Inserting the video element in the body var video = document.createElement("video"); document.body.appendChild(video); //Array where the arrayBuffers will be stored var parts = []; client.on('stream', function(stream,meta){ stream.on('data',function(data){ parts.push(data); }); stream.on('end',function(){ video.src = (window.URL||window.webkitURL).createObjectURL(new Blob(parts.slice(0,500))); $('video')[0].play(); $('video')[0].controls=true; }) }); 请注意,为了实现目标,我只给部分接收到的数据( parts.slice(0,500) )提供了Blob构造函数。 上面的代码不起作用,除非我给Blob提供整个接收的数据 – […]

在大表中使用node.js中的mysql模块

我在我的MySQL数据库(大约一千万行)有一个大的表,我需要把所有这些数据转换成JSON格式。 对于较小的表,我会使用基本的connection.query("SELECT * FROM TABLE, function(err, results) {}); syntax。但是,我不想将整个表加载到内存中。 我注意到,mysql模块有能力“stream”行( https://github.com/felixge/node-mysql/#streaming-query-rows ),所以我想知道是否仍然将整个表加载到内存和那么只是给我们一行一行,或者它实际上每次只加载一行,所以整个表不会一次存储在内存中。