所以我试图一次读取一个文件字节。基本上我应该读取前50个字节,然后接下来的7个字节应该告诉我长度x。然后我读取x个字节并重复这些步骤直到文件结束。我被卡住了。不知道该怎么办。任何帮助将不胜感激。
app.get('/video', function (req, res) {
var readStream = fs.createReadStream('video.mjpeg');
res.writeHead(200, {'Content-Type': 'multipart/x-mixed- replace;boundary=ThisString'});
readStream.on("data", (chunk) => {
console.log(chunk.length); //this always gives me the same number.
res.write(chunk, 'binary');
console.log("Writing to client");
});
readStream.on("end", () => {
readStream.destroy();
res.end();
console.log("End of data");
});
});
基本上我想将数据分组到帧中。谢谢。