我是cote.js(http://cote.js.org/)的新手,虽然它是一个方便的框架,但我发现很难在请求/响应中嵌入二进制文件。
例如,如果我提出请求:
const cote = require('cote');
const requester = new cote.Requester({ name: 'test' });
const request = { type: 'test', binary: toString(binary) };
requester.send(request, (res) => {
var returnedBinary = new Buffer(res);
// do something with the returned binary
});
然后在服务器端我会这样做:
const cote = require('cote');
const responder = new cote.Responder({ name: 'test' });
responder.on('test', (req, cb) => {
var newBinary = new Buffer(req.binary);
// do something with the new binary
cb(toString(newBinary));
});
看到这里我一直将二进制转换为字符串,然后将其转换回来。这对我来说似乎适得其反。有没有办法直接请求和回复二进制文件?