I'm wondering what would be the best way to check if a file is binary or ASCII with Node.js?
There appears to be two ways not specific to node.js:
Checking the MIME type: How to Check if File is ASCII or Binary in PHP - however this has it's problems, as for instance pre-precessors often don't have a recognised mime type and revert to application/octet-stream
when checking them using mime
Via checking the byte size using a stream buffer with How to identify the file content as ASCII or binary - which seems quite intensive, and does yet provide a node.js example.
So is there another way already? Perhaps a secret node.js call or module that I don't know about? Or if I have to do this myself, what way would be suggested?
Thanks
Thanks to the comments on this question by David Schwartz, I created istextorbinary to solve this problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With