-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
response.download does not return /proc/* files #4944
Comments
Hi @mleblebici yes, I agree they should be able to work. Unfortunately I just use Windows mainly and don't really have experience there on what would be wrong. Express is just using |
Hi @dougwilson, it seems the problem stems from send module. Normally fs.createReadStream is able to read contents of /proc/* files, but when using send module, it introduces a problem somewhere. I used following code and it was not able to read the contents.
|
Hi @mleblebici thanks for investigating! Can you open a bug over there? Ideally if you can open a pull request with a fix, as I don't think I can personally fix it due to not having the /proc/ stuff on my system to use for testing what is wrong. |
Hi @dougwilson , I also investigated the problem with send library. It seems fs.stat returns size of 0 for /proc/* files. So, I added a getSize function to correctly get size of /proc/* files. It fixed the problem. But, as I am not a developer (especially not a JS developer), you should probably check to make sure it does not cause any performance issue or create any additional bug. |
Thanks! Have you checked with the Node.js project that fs.stat returning a size of 0 for those files is not simply a bug in their stat function? We'll want some kind of confirmation before landing a change like that. |
Virtual files such as |
Thanks @krzysdz ! Well, that sucks, as normal files that are zero size also return zero :( |
Btw, you may want to check this one nodejs/node#43669 |
Well, if the file size is zero, maybe don't set the |
the response.download function uses pillarjs/send which uses fs.stat to get the size of the file and set the http headers accordingly. then uses the size to generat fs.createReadStream options (start , end ) which is (0,0) this contributes to reciving an empty file.
const path = '/proc/meminfo';
// set the header so that the file will download instead of show in the browser
res.setHeader('Content-Disposition',' attachment; filename="meminfo"')
fs.createReadStream(path, 'utf-8').pipe(res); |
response.download() returns empty for file under /proc directory like /proc/meminfo, /proc/cpuinfo and others. /proc is a pseudo filesystem, but these files' content can be readable with fs.readFile. I think it should also be readable with response.download and response.sendFile.
The text was updated successfully, but these errors were encountered: