472,139 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

Distinguish between binary and text files

Hi,

I need a test so I can determine whether a url points to a text file or to a
binary file. Actually, I need to distinguish between streaming files and
metafiles (e.g. asx files). I tried getmimetype, but that does not seem te
be reliab;e (dependent on the web server configuration). Can anyone help?
The test should be something like:

get url
if isbinaryfile ($url) {
do what you need to do with streaming files
} else {
do what you need to do with text files
}

Thanks,
André Rosendaal
Jul 17 '05 #1
1 2131

You could try the algorithm used by - amongst others - the diff tool:

"...diff determines whether a file is text or binary by checking the
first few bytes in the file; the exact number of bytes is system
dependent, but it is typically several thousand. If every byte in that
part of the file is non-null, diff considers the file to be text;
otherwise it considers the file to be binary."
Non-null just means any character other than ASCII 0.

---
Steve

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

27 posts views Thread by Eric | last post: by
12 posts views Thread by Sunner Sun | last post: by
15 posts views Thread by miki | last post: by
10 posts views Thread by joelagnel | last post: by
3 posts views Thread by nicolasg | last post: by
15 posts views Thread by JoeC | last post: by
3 posts views Thread by masood.iqbal | last post: by
9 posts views Thread by deepakvsoni | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.