🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #16591

Re: Ascii or binary file

#16591
From: Andrue Cope
Date: Thu, 08 May 2003 13:20
26 lines
1890 bytes
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]
Technical Details
Message-ID: <VA.00001c9d.01332329@email.address.sorry>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed.icl.net!newsfeed.fjserv.net!newshosting.com!news-xfer2.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3eba4f4a@newsgroups.borland.com>

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 06:29:07 PST
Date: Thu, 08 May 2003 14:20:55 +0100
Newsgroups: borland.public.cppbuilder.nativeapi
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va
Message-ID: <VA.00001c9d.01332329@email.address.sorry>
Subject: Re: Ascii or binary file
From: Andrue Cope <not.a.valid@email.address.sorry>
Reply-To: not.a.valid@email.address.sorry
References: <3eba4f4a@newsgroups.borland.com>
NNTP-Posting-Host: 217.207.223.34
X-Trace: newsgroups.borland.com 1052400055 217.207.223.34 (8 May 2003 06:20:55 -0700)
Lines: 27
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed.icl.net!newsfeed.fjserv.net!newshosting.com!news-xfer2.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail