Thread overview
std.file.read || writefln
Jun 16, 2006
MM
Jun 16, 2006
MM
Jun 17, 2006
Derek Parnell
Jun 17, 2006
MM
Jun 17, 2006
Markus Dangl
June 16, 2006
Why do I get:
MZ` ☺   ♦ ►
An exception occured: 4invalid UTF-8 sequence

From:
http://www.docwiki.net/view.php?pageid=150

The content of the file doesn't matter afaik :)
Just some simple .txt file in ansi or unicode.. (windowsxp)


June 16, 2006
"MM" <MM_member@pathlink.com> wrote in message news:e6v3hk$b1u$1@digitaldaemon.com...
> Why do I get:
> MZ` &#9786;   &#9830; &#9658;
> An exception occured: 4invalid UTF-8 sequence
>
> From:
> http://www.docwiki.net/view.php?pageid=150
>
> The content of the file doesn't matter afaik :)
> Just some simple .txt file in ansi or unicode.. (windowsxp)

That's an interesting bug.  Notice the "MZ" at the beginning of your output - that's the header for an EXE file.  What's going on is that args[0] is actually the name of the running program - that is, if you compile this program as "test.d", the program will be "test.exe" - so when you type in

test something.txt

On the command line, the args[][] array is populated with:

["test.exe", "something.txt"]

So args[0] is the name of the program.

Change it to args[1], and it should work.  And update that wiki article while you're at it ;)


June 16, 2006
>Change it to args[1], and it should work.  And update that wiki article while you're at it ;)
>

Ay sir, I will as soon as you tell me what the best way to read raw data is.. from the beginning, byte for byte, till end of file :D

(while I'm waiting for my registration email to come to me :)
and thx


June 17, 2006
On Sat, 17 Jun 2006 08:02:49 +1000, MM <MM_member@pathlink.com> wrote:

>
>> Change it to args[1], and it should work.  And update that wiki article
>> while you're at it ;)
>>
>
> Ay sir, I will as soon as you tell me what the best way to read raw data is..
> from the beginning, byte for byte, till end of file :D
>
> (while I'm waiting for my registration email to come to me :)
> and thx

It wasn't the reading that caused the crash but trying to write the raw data as if it was char[] (UTF8). You have to treat raw data as ubyte[] or byte[] depending on how you will use it.

-- 
Derek Parnell
Melbourne, Australia
June 17, 2006
Jarrett Billingsley schrieb:
> "MM" <MM_member@pathlink.com> wrote in message news:e6v3hk$b1u$1@digitaldaemon.com...
>> Why do I get:
>> MZ` &#9786;   &#9830; &#9658;
>> An exception occured: 4invalid UTF-8 sequence
>>
>> From:
>> http://www.docwiki.net/view.php?pageid=150
>>
>> The content of the file doesn't matter afaik :)
>> Just some simple .txt file in ansi or unicode.. (windowsxp)
> 
> That's an interesting bug.  Notice the "MZ" at the beginning of your output - that's the header for an EXE file.  What's going on is that args[0] is actually the name of the running program - that is, if you compile this program as "test.d", the program will be "test.exe" - so when you type in
> 
> test something.txt
> 
> On the command line, the args[][] array is populated with:
> 
> ["test.exe", "something.txt"]
> 
> So args[0] is the name of the program.
> 
> Change it to args[1], and it should work.  And update that wiki article while you're at it ;) 

This is a bad example, i corrected it. Using writefln for binary data isn't a thing you want to do normally ;)
June 17, 2006
>It wasn't the reading that caused the crash but trying to write the raw data as if it was char[] (UTF8). You have to treat raw data as ubyte[] or byte[] depending on how you will use it.
>
>-- 
>Derek Parnell
>Melbourne, Australia

Somehow my last post got lost... here it is again :)
I wanted to read a file without having to put the whole thing in mem.. Or doen't
read do this?
If there is some way to read a file byte for byte how do I know end_of_file?
(I also didn't recieve the registration email from the docwiki... I'll try that
again too, although the problem is already corrected :)


June 17, 2006
"MM" <MM_member@pathlink.com> wrote in message news:e71o47$c4v$1@digitaldaemon.com...

> Somehow my last post got lost... here it is again :)
> I wanted to read a file without having to put the whole thing in mem.. Or
> doen't
> read do this?
> If there is some way to read a file byte for byte how do I know
> end_of_file?
> (I also didn't recieve the registration email from the docwiki... I'll try
> that
> again too, although the problem is already corrected :)

Use std.stream.File, or std.stream.BufferedFile.  To see if you're at the end of the file, use the .eof() method for either of those.