我有一个server-app
从客户端接收音频流.我正在尝试使用chai
/ 测试应用程序chai-http
,但它给了我这个错误:
[错误:结束后写]
有什么问题?
码:
var chai = require('chai'); var chaiHttp = require('chai-http'); var server = require('../server-app'); var should = chai.should(); var fs = require('fs'); chai.use(chaiHttp); describe('server', function() { it('should work..', function (done){ var req = chai.request(server).post('/speech'); fs.createReadStream('./test.wav').pipe(req); req.end(function (err,res){ console.log(err);//outputs: [Error: write after end] done(); }); }); });
Quy.. 5
您在req.end
流完成将数据推送到请求之前调用.
我会做以下事情:
var readstream = fs.createReadStream('./test.wav'); readstream.pipe(req); readstream.on('close', someFunction); readstream.on('end', someFunction);
并调用流req.end
的关闭或结束事件.在发出这些事件之前,您正在调用req.end.
您在req.end
流完成将数据推送到请求之前调用.
我会做以下事情:
var readstream = fs.createReadStream('./test.wav'); readstream.pipe(req); readstream.on('close', someFunction); readstream.on('end', someFunction);
并调用流req.end
的关闭或结束事件.在发出这些事件之前,您正在调用req.end.