音乐\视频播放
app.get('/video', (req, res) => {
if(!req.headers.range) return res.end()
const fileSize = 13915992
const range = req.headers.range
const parts = range.replace(/bytes=/, "").split("-")
let start = parseInt(parts[0], 10)
let end = parts[1]
? parseInt(parts[1], 10)
: fileSize - 1
const chunksize = (end - start) + 1
let head = {
'Content-Range': 'bytes ' + start + '-' + end + '/' + fileSize,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': 'video/mp4'
}
let readeStream = fs.createReadStream('index.mp4', {
start,
end: undefined
})
res.writeHead(206, head)
readeStream.pipe(res)
});