HTTP 분할 다운로드 서버
http.createServer(function (req, res) {
fs.access(path, (err) => {
if(err){
res.writeHead(404, { "Content-type": "text/plain" });
res.write("404 Not Found\n");
res.end();
return;
}
else{
const range = req.headers.range;
let [start, end] = range.replace(/bytes=/, "").split("-");
start = parseInt(start);
end = parseInt(end);
res.statusCode = 206;
res.write(data.subarray(start, end + 1), "binary");
res.end();
}
});
}).listen(5500)
응답 메시지
202 OK:
206 Partial Content:
404 Not Found:
'Media' 카테고리의 다른 글
ffmpeg shaka packger로 인코딩, mpd 파일 생성하기 (0) | 2023.02.03 |
---|---|
node.js 비디오 비교하기 (0) | 2023.02.03 |
bittorrent 정리 (0) | 2023.02.03 |