473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ascii or binary

Hello,

I'm searching to know if a local file is ascii or binary.
I couldn't find it in the manual, is there a way to know that ?

thanks,

--
greg
Mar 13 '06 #1
13 3524

greg wrote:
Hello,

I'm searching to know if a local file is ascii or binary.
I couldn't find it in the manual, is there a way to know that ?

thanks,

--
greg


AFAIK it depends on what kind of file it is. Not sure, but ascii are
txt, csv, html etc, binary are images, mp3's etc.
Correct me if i'm wrong.

Mar 13 '06 #2

greg wrote:
Hello,

I'm searching to know if a local file is ascii or binary.
I couldn't find it in the manual, is there a way to know that ?

thanks,

--
greg


<http://www.php.net/mb_detect_encoding>

Mar 13 '06 #3
>
<http://www.php.net/mb_detect_encoding>

excuse my ignorance, but do you mean that if this function returns "ascii",
it's ascii ... if not it's binary ?
I'm not really sure to get your tip.

--
greg
Mar 13 '06 #4
AFAIK it depends on what kind of file it is. Not sure, but ascii are
txt, csv, html etc, binary are images, mp3's etc.
Correct me if i'm wrong.


surely, but this means I must think of all the possible file extension
decide whether it's ascii or binary.
it seems to be limited, but thx anyway.

--
greg
Mar 13 '06 #5
greg wrote:
AFAIK it depends on what kind of file it is. Not sure, but ascii are
txt, csv, html etc, binary are images, mp3's etc.
Correct me if i'm wrong.


surely, but this means I must think of all the possible file extension
decide whether it's ascii or binary.
it seems to be limited, but thx anyway.


In a sense he is right, it is not really straightforward to make the
distinction, if you strictly mean the ascii character set.

Binary just means that it consists of binary patterns or sequence of
bits, varied in length and meaning. The content of a binary file only
makes sense to an application which knows what the sequence of bits
means. When a file is viewed in a text-editor, then the data is
(possibly mistakenly) chopped up in 8-bits (or whatever), and the
corresponding symbol of that value is displayed, which may or may not
make any sense at all. Strictly speaking, the only difference between
ascii and non-ascii would be whether or not each chunk of bits is
*intended* to correspond to a specific symbol in the Ascii character
table.

If you by ascii generally mean plain readable/printable text, not
necessarilly limited to ascii, then there is tools that could help you.

http://dk2.php.net/mime_content_type
http://pecl.php.net/package/fileinfo

If you are on a linux/unix, check:
http://www.freebsd.org/cgi/man.cgi?query=file

You could just ignore the subtype, and only distinguish on mediatype
between text and everything else.

/Bent
Mar 14 '06 #6
> In a sense he is right, it is not really straightforward to make the
distinction, if you strictly mean the ascii character set.

Binary just means that it consists of binary patterns or sequence of bits,
varied in length and meaning. The content of a binary file only makes
sense to an application which knows what the sequence of bits means. When
a file is viewed in a text-editor, then the data is (possibly mistakenly)
chopped up in 8-bits (or whatever), and the corresponding symbol of that
value is displayed, which may or may not make any sense at all. Strictly
speaking, the only difference between ascii and non-ascii would be whether
or not each chunk of bits is *intended* to correspond to a specific symbol
in the Ascii character table.

If you by ascii generally mean plain readable/printable text, not
necessarilly limited to ascii, then there is tools that could help you.

http://dk2.php.net/mime_content_type
http://pecl.php.net/package/fileinfo

If you are on a linux/unix, check:
http://www.freebsd.org/cgi/man.cgi?query=file

You could just ignore the subtype, and only distinguish on mediatype
between text and everything else.

/Bent


Thank you for these explanations.
In fact, I should have told why I want know make the difference between
ascii and binary files.
I have a list of files to send via FTP from a local machien to a remote
server.
the ftp_put function needs an argument that can be FTP_ASCII or FTP_BINARY.
I don't know how to choose dynamicaly this argument as the must upload
various file types.

tia,

--
greg
Mar 14 '06 #7
"greg" <gr**@no-spam.org> wrote in message
news:44**********************@news.free.fr...
In a sense he is right, it is not really straightforward to make the
distinction, if you strictly mean the ascii character set.

Binary just means that it consists of binary patterns or sequence of
bits, varied in length and meaning. The content of a binary file only
makes sense to an application which knows what the sequence of bits
means. When a file is viewed in a text-editor, then the data is (possibly
mistakenly) chopped up in 8-bits (or whatever), and the corresponding
symbol of that value is displayed, which may or may not make any sense at
all. Strictly speaking, the only difference between ascii and non-ascii
would be whether or not each chunk of bits is *intended* to correspond to
a specific symbol in the Ascii character table.

If you by ascii generally mean plain readable/printable text, not
necessarilly limited to ascii, then there is tools that could help you.

http://dk2.php.net/mime_content_type
http://pecl.php.net/package/fileinfo

If you are on a linux/unix, check:
http://www.freebsd.org/cgi/man.cgi?query=file

You could just ignore the subtype, and only distinguish on mediatype
between text and everything else.

/Bent


Thank you for these explanations.
In fact, I should have told why I want know make the difference between
ascii and binary files.
I have a list of files to send via FTP from a local machien to a remote
server.
the ftp_put function needs an argument that can be FTP_ASCII or
FTP_BINARY.
I don't know how to choose dynamicaly this argument as the must upload
various file types.

I suppose you could just send binary always.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Mar 14 '06 #8
greg wrote:
[snip]
Thank you for these explanations.
In fact, I should have told why I want know make the difference between
ascii and binary files.
I have a list of files to send via FTP from a local machien to a remote
server.
the ftp_put function needs an argument that can be FTP_ASCII or FTP_BINARY.
I don't know how to choose dynamicaly this argument as the must upload
various file types.


The only purpose of ascii transfer is to translate line-endings
(CR,LF,CRLF) between differing systems, but many text-editors can
handle any type, so always using binary as Kimmo suggest is a good
option, since this leaves files intact, whereas using ascii by mistake
could render a file useless.

Although I would think that to use ascii-transfer if and only if file
has an extension of ".txt" should be safe.

/Bent
Mar 14 '06 #9
Kimmo Laine wrote:
"greg" <gr**@no-spam.org> wrote in message
news:44**********************@news.free.fr...
In a sense he is right, it is not really straightforward to make the
distinction, if you strictly mean the ascii character set.

Binary just means that it consists of binary patterns or sequence of
bits, varied in length and meaning. The content of a binary file only
makes sense to an application which knows what the sequence of bits
means. When a file is viewed in a text-editor, then the data is (possibly
mistakenly) chopped up in 8-bits (or whatever), and the corresponding
symbol of that value is displayed, which may or may not make any sense at
all. Strictly speaking, the only difference between ascii and non-ascii
would be whether or not each chunk of bits is *intended* to correspond to
a specific symbol in the Ascii character table.

If you by ascii generally mean plain readable/printable text, not
necessarilly limited to ascii, then there is tools that could help you.

http://dk2.php.net/mime_content_type
http://pecl.php.net/package/fileinfo

If you are on a linux/unix, check:
http://www.freebsd.org/cgi/man.cgi?query=file

You could just ignore the subtype, and only distinguish on mediatype
between text and everything else.

/Bent


Thank you for these explanations.
In fact, I should have told why I want know make the difference between
ascii and binary files.
I have a list of files to send via FTP from a local machien to a remote
server.
the ftp_put function needs an argument that can be FTP_ASCII or
FTP_BINARY.
I don't know how to choose dynamicaly this argument as the must upload
various file types.


I suppose you could just send binary always.


No, that will screw up the file if you're going between different OS's
such as Windows and Unix. There's a reason why there are different
transfer modes!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 14 '06 #10
Bent Stigsen wrote:
greg wrote:
[snip]
Thank you for these explanations.
In fact, I should have told why I want know make the difference
between ascii and binary files.
I have a list of files to send via FTP from a local machien to a
remote server.
the ftp_put function needs an argument that can be FTP_ASCII or
FTP_BINARY.
I don't know how to choose dynamicaly this argument as the must upload
various file types.

The only purpose of ascii transfer is to translate line-endings
(CR,LF,CRLF) between differing systems, but many text-editors can handle
any type, so always using binary as Kimmo suggest is a good option,
since this leaves files intact, whereas using ascii by mistake could
render a file useless.

Although I would think that to use ascii-transfer if and only if file
has an extension of ".txt" should be safe.

/Bent


Transferring a text file from Windows to Unix will cause problems in VIM
and many other Unix editors. And not all Windows editors support
Unix-style nl characters.

Better to determine if it's a text file, and only if unknown default to
binary.

Alternatively, scan the file for non-char values.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 14 '06 #11
>
Transferring a text file from Windows to Unix will cause problems in VIM
and many other Unix editors. And not all Windows editors support
Unix-style nl characters.

Better to determine if it's a text file, and only if unknown default to
binary.

Alternatively, scan the file for non-char values.


Ok, I'm gonna use this solution.
Thank you all for your help.

--
greg
Mar 14 '06 #12
Jerry Stuckle wrote:
Bent Stigsen wrote: [snip]
The only purpose of ascii transfer is to translate line-endings
(CR,LF,CRLF) between differing systems, but many text-editors can
handle any type, so always using binary as Kimmo suggest is a good
option, since this leaves files intact, whereas using ascii by mistake
could render a file useless.

Although I would think that to use ascii-transfer if and only if file
has an extension of ".txt" should be safe.

/Bent


Transferring a text file from Windows to Unix will cause problems in VIM
and many other Unix editors. And not all Windows editors support
Unix-style nl characters.


Those bastards. Well, they just have to change. Other transfer
protocols or portable storage devices makes it impossible to control
anyway, so (using a bad analogy) insisting on proper conversion when
using ftp is like waving a hand to stop a hurricane.

If the destination is a web-folder or accessed in an alternative way
by different clients, it doesn't matter in the slightest, or in worst
case even a bad idea.
Better to determine if it's a text file, and only if unknown default to
binary.


I understand that it was designed that way, so that things was neat
and tidy in both camps, but the battle of the line-endings is already
lost to chaos, nothing short of a revolution is going to change that.

/Bent

[snip]
Mar 14 '06 #13
ZeldorBlat wrote:

greg wrote:
Hello,

I'm searching to know if a local file is ascii or binary.
I couldn't find it in the manual, is there a way to know that ?

thanks,

--
greg


<http://www.php.net/mb_detect_encoding>


Hi,

You made me curious. :-)

How can that function diffentiate between encodings?
How is that done?

I mean: The string contains a set of numbers behind the scene that have a
certain corresponding character depending on the characterset used.

Now it looks the other way around: It's like the string also contains
information on what encoding is used for it.
It that true?

I must be missing something completely.

Can anybody explain how this function works?

TIA

Regards,
Erwin Moller
Apr 6 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bix | last post by:
As this is my very first post, I'd like to give thanks to all who support this with their help. Hopefully, this question hasn't been answered (too many times) before... If anyone could explain...
8
by: Bernhard Hidding | last post by:
Hi, my program writes chars to an ascii file via ofstream. You can use "\n" for newline and "\t" for tab there, but is there any command that deletes the last char in the current ofstream? Thanks...
22
by: Sunner Sun | last post by:
Hi, all Since the OS look both ASCII and binary file as a sequence of bytes, is there any way to determine the file type except to judge the extension? Thank you!
5
by: sathyashrayan | last post by:
Group, I have some doubts in the following program. ------------------program--------------------- /* ** Make an ascii binary string into an integer. */ #include <string.h> unsigned int...
6
by: SandyMan | last post by:
Hi, I am able to open a binary file for reading but can someone tell me as how to go about converting a Binary file to ASCII file using C. Thanks In Advance SandyMan
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
6
by: as400tips | last post by:
I have a Binary Data file (Packed Decimal and ASCII mixed) and would like to convert into ASCII (readable) file. How to do it in C#? Thanks.
7
by: azrael | last post by:
Hy folks, I googled, and searched, and can not bealive that I have not found a built in way to convert the easy and elegant python way a function to easily convert simple ascii data to binary...
5
by: Canned | last post by:
Hi, I'm trying to write a class that can convert ascii to binary and vice versa. I write my class based on this function I've found on internet That works perfectly, but when I try to implement...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.