Hi, 
I’ve been lurking for a few weeks. I know streaming, and I know serving 
audio and video files. My first project had to stream av files so I learned 
how to do it with node. You need to work with content-length and you need 
to send 206s instead of 200s when you get a range request.

function send(err,data){
if (err)
return send404(fileName)
cache.put(fileName,data,600000) // 10 minutes
var range = request.headers.range // bytes=0-1
if (!range){
response.writeHead(200, {
"Content-Type": mimeType,
"X-UA-Compatible": "IE=edge;chrome=1",
'Content-Length': data.length
});
response.end(data)
}else{
var total = data.length,
split = range.split(/[-=]/),
ini = +split[1],
end = split[2]?+split[2]:total-1,
chunkSize = end - ini + 1
response.writeHead(206, { 
"Content-Range": "bytes " + ini + "-" + end + "/" + total, 
"Accept-Ranges": "bytes",
"Content-Length": chunkSize,
"Content-Type": mimeType
})
response.end(data.slice(ini, chunkSize+ini))
// console.log('send',ini,chunkSize,end,total)
}
}


Jake

On Thursday, April 24, 2014 12:08:45 PM UTC-7, Jonathan Chetwynd wrote:
>
> hunting about:
>
> http://stackoverflow.com/questions/11458107/nsurlerrordomain-cannot-decode-raw-data
> suggest content-length maybe required
>
> not clear to me that
> Buffer.byteLength(string, [encoding])
> is appropriate for .mp4 files
>
>
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to