res.download() Range support
What is this? it shows up when i try to route a download link in expressjs. Here is my code.
server.get('/download/files/*.*', function(req, res){
var downloadPath = './files/' + path.basename(unescape(req.url));
path.exists(downloadPath, function(exists){
if(exists)
res.download(downloadPath);
else
res.send(404);
});
});
Edit: Also include the filename it trying to parse.
Zzzzzzzz ZZ Zzzzzz Zzz ZZZZ Zzzzzzz Zzzzzzzzzzz_zzzzzzzzzzz.zzzz_zz_ZZZZZZZ_Z.zzzz1.rar
Edit2: FileSize
943 MB
hmm not sure what your exact issue is, usually I only get segfaults with cyclic require()s in node. Anyways I added ./examples/download to show you how to use that functionality, so give that a look :)
Hmm.. maybe because the file size. This doesn't shows up when downloading a small file.
Edit2: Why don't you use createReadStream instead of readFile? Imagine 943MB was inserted to a buffer then was sent one time?. If you use createReadStream, it will be easy enough to support Range right?
yes that would be to big. Ideally we would transfer small files with readFile(), I will create a new issue for this
maybe what we should do, at least eventually is abstract out connect's staticProvider serving code, so we can use that with res.download() for private files. But for now I will add a "stream threshold" setting, so larger files can be streamed via sys.pump()
Hmm... can you update the example on how to use the stream threshold setting?
Edit : I've already see the documentation and I only need to set it to true right? One more, how about range? Did express support it already? This is important to my visitors because Sometimes there will got visitors who failed to connect in the middle of the downloading process. So it will be a burden for them to start the same download again. Imagine if it stuck at the same place again and again.
Since for smaller files readFile() is quite a bit faster and allows recovery of missing files etc, we will stream only when >= "stream threshold" which defaults to 32k at the moment, you can change this by using app.set("stream threshold", 64 * 1024) etc.
I do agree though, we will work something out. Perhaps for small files it is irrelevant since they would transfer (or re-transfer) quickly, but for those which we stream lets add Range support, I will reopen this with a new title
yikes, ok node has a small but nasty bug (patched here http://github.com/visionmedia/node/commit/f867493b8ef4efd14aa324d8d89347602c33bbe5) preventing this from working, however I will push the Range branch up so we can hack on that
Owh. Then I should wait until you finally "hack" it though. Since my node application are really depending on the "Range" feature. One more, about this stream threshold. Is it in bytes or kilo bytes or megabytes?
its in bytes, so you need to do 64 * 1024 or whatever you want. I have the "Range" branch up, and can merge when the next node is released with the bugfix. Currently I only support one range though, we need to work on the multipart
Ooo.. So this means that it will fail on using download accelerator? Dunno what do you mean by multipart :P
the range specification mentions that you can request several ranges, and then the response must be a multipart response much like a multipart file upload would be
I've been watching for a long time. Is there any update for this request?
0.2.3 was just released, so I can merge this in now. Have you looked at the range branch? will merge in a bit
merged it in. feel free to take a look and tweak as needed but should be fine
Yep, I've looked at the range branch everyday :P. Wow, thanks man! I will try it out. I will see if anything wrong happens.
I cant remember (will have to check) but I think the spec mentioned that if you are to support Range at all, you have to support multiple range support, which kinda sucks :s it will become quite a bit larger if that is the case
closing for now, let me know if you come across any issues with this feature