I am creating a music web app that streams MP3s that I have stored in MongoDB(GridFS).
My Question: How can I add http range support so that I can start streaming the audio file 1/2 of the way through without having to wait for the buffer.
I know GridFS supports reading for X bytes – X bytes, so basically I just need to know how to get nodejs to understand it only needs bytes X – X.
Thanks!
The client will send a
Rangeheader specifying the absolute starting and ending bytes followed by total file length or ‘*’.Examples:
The server should then return a response code
206(Partial content) and theContent-Lengthshould be only the amount of data transmitted.In the case the range is wrong, the server should either return
416(Requested range not satisfiable) with aContent-Rangefield ofbytes */*or should ignore the range request and return a200with the entire body of the file.The server must also send an
Accept-Rangesfield with the value of the accepted range unit, in this casebytes. But the range unit can be any custom range unit you want.Source: rfc2616