Article View: borland.public.cppbuilder.nativeapi
Article #16595Re: Ascii or binary file
From: Jim Dodd
Date: Thu, 08 May 2003 14:35
Date: Thu, 08 May 2003 14:35
43 lines
2620 bytes
2620 bytes
Andrue Cope wrote:
> Johnny Liwis,
>
>
>>How do I know if the file has binary or ascii content ?
>>
>
>
> All you can do is scan the entire files and determine if all the byte
> values lie within the acceptable range for 'ascii content' whatever
> that is.
>
> FWIW we have a routine that does a pretty good job at this kind of
> thing. We use it to decide whether to activate a hex view or text
> view. The decision is based upon the following function:
>
> bool TOTextLineIndexer::IsMainlyTextual()
> {
> return !( ( MyFileSize-MyViewableText )>( 3*MyViewableText ) );
> }
>
> Where MyViewableText is the count of bytes whose values lie within
> the range 32 (space) to 0x7F.
>
> I can't give particular statistics for success but we use it a lot
> and it chooses the right mode most of the time.
>
> Andrue Cope
> [Bicester, UK]
>
I use a similar scheme to this but also include the values 9 (Tab), 10
(Line Feed) and 13 (Carriage Return) in the list of values that are
considered "text". Sometimes, I even include the value 8 (Backspace).
And in some DOS files, you might want to include 26 (Ctrl-Z) in the list
of "text" characters becuase it is sometimes used to mark the end of file.
In this way, we don't use Andrue's "times 3" fudge factor. We just say
that if ANY character falls out side the range [8,9,10,13,26,32-127],
the file is probably a binary file.
Jim Dodd
Onset Computer Corp.
Technical Details
Message-ID:
<3eba6b37$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3eba4f4a@newsgroups.borland.com> <VA.00001c9d.01332329@email.address.sorry>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,65ce5fe967ca5eb X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-08 07:44:20 PST Date: Thu, 08 May 2003 10:35:33 -0400 From: Jim Dodd <bcbuilderboy@yahoo.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Ascii or binary file References: <3eba4f4a@newsgroups.borland.com> <VA.00001c9d.01332329@email.address.sorry> In-Reply-To: <VA.00001c9d.01332329@email.address.sorry> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 65.161.163.42 Message-ID: <3eba6b37$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1052404535 65.161.163.42 (8 May 2003 07:35:35 -0700) Lines: 44 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail