Read image case insensitive or regex.

39 views
Skip to first unread message

Gonçalo Diogo Bessa

unread,
Nov 21, 2014, 10:19:55 PM11/21/14
to nod...@googlegroups.com

Hello everyone,


Someone know if it's possible read a file when path is case insensitive?


Some providers changes my path. So can't find image for client.


fs.stat(file, function (err, stat) {
var img = fs.readFileSync(file);
res.contentType = path.extname(file);
res.contentLength = stat.size;
res.end(img, 'binary');
});


Thanks,

Ryan Schmidt

unread,
Nov 22, 2014, 11:07:00 AM11/22/14
to nod...@googlegroups.com
Are you saying you're getting a file-not-found error because you're on a case-sensitive filesystem and the case of the file stored on disk is different from the case with which you're trying to read it? If so, the solution is to use the correct case in your code. If you're asking if there is a way to figure out the correct case programmatically, then that's not the correct solution to use--not in production code. If you read the directory contents you could compare the filenames case-insensitively with the one you're looking for, but on a case-sensitive filesystem there's no guarantee there wouldn't be multiple matches.


Gonçalo Diogo Bessa

unread,
Nov 24, 2014, 6:19:36 AM11/24/14
to nod...@googlegroups.com

Thank you for help Schmidt.





--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/E7749CBE-1440-49F0-82B7-F7FA2AAF4CE3%40ryandesign.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages