Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Check if a file is binary or ASCII with Node.js?

Check if a file is binary or ASCII with Node.js?

Problem

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:

  1. 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

  2. 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

Problem courtesy of: balupton

Solution

Thanks to the comments on this question by David Schwartz, I created istextorbinary to solve this problem.

Solution courtesy of: balupton

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Check if a file is binary or ASCII with Node.js?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×