Thread overview
Reading a file using stream.
Jan 18, 2006
Carlos Madureira
Jan 18, 2006
Ben Hinkle
Jan 20, 2006
Hasan Aljudy
Jan 20, 2006
Ben Hinkle
January 18, 2006
I was looking at the code in samples/d2html.d and it doesn't use it but waits for a exception to get out of the while loop.

I want to read a file in chunks, but the exception doesn't seem like a good mechanism to exit the while loop and the implementation of eof() for files seems slow since it uses seeking.

InputStream is = File("test.txt");
while (is.eof())
{
is.read(buffer);
..
}


January 18, 2006
"Carlos Madureira" <Carlos_member@pathlink.com> wrote in message news:dqm5gc$193c$1@digitaldaemon.com...
>I was looking at the code in samples/d2html.d and it doesn't use it but waits
> for a exception to get out of the while loop.
>
> I want to read a file in chunks, but the exception doesn't seem like a
> good
> mechanism to exit the while loop and the implementation of eof() for files
> seems
> slow since it uses seeking.
>
> InputStream is = File("test.txt");
> while (is.eof())
> {
> is.read(buffer);
> ..
> }
>
>

use a std.stream.BufferedFile or a std.cstream.CFile (which is buffered by the C runtime). Unbuffered file i/o will be slow. Also not I think you want while (!is.eof()).


January 20, 2006
Ben Hinkle wrote:
> "Carlos Madureira" <Carlos_member@pathlink.com> wrote in message news:dqm5gc$193c$1@digitaldaemon.com...
> 
>>I was looking at the code in samples/d2html.d and it doesn't use it but waits
>>for a exception to get out of the while loop.
>>
>>I want to read a file in chunks, but the exception doesn't seem like a good
>>mechanism to exit the while loop and the implementation of eof() for files seems
>>slow since it uses seeking.
>>
>>InputStream is = File("test.txt");
>>while (is.eof())
>>{
>>is.read(buffer);
>>..
>>}
>>
>>
> 
> 
> use a std.stream.BufferedFile or a std.cstream.CFile (which is buffered by the C runtime). Unbuffered file i/o will be slow. Also not I think you want while (!is.eof()). 
> 
> 

"is" is a keyword! Cannot be used as an identifier.
January 20, 2006
"Hasan Aljudy" <hasan.aljudy@gmail.com> wrote in message news:dqpmaa$1896$1@digitaldaemon.com...
> Ben Hinkle wrote:
>> "Carlos Madureira" <Carlos_member@pathlink.com> wrote in message news:dqm5gc$193c$1@digitaldaemon.com...
>>
>>>I was looking at the code in samples/d2html.d and it doesn't use it but
>>>waits
>>>for a exception to get out of the while loop.
>>>
>>>I want to read a file in chunks, but the exception doesn't seem like a
>>>good
>>>mechanism to exit the while loop and the implementation of eof() for
>>>files seems
>>>slow since it uses seeking.
>>>
>>>InputStream is = File("test.txt");
>>>while (is.eof())
>>>{
>>>is.read(buffer);
>>>..
>>>}
>>>
>>>
>>
>>
>> use a std.stream.BufferedFile or a std.cstream.CFile (which is buffered by the C runtime). Unbuffered file i/o will be slow. Also not I think you want while (!is.eof()).
>
> "is" is a keyword! Cannot be used as an identifier.

hehe. good point. I totally missed that one. Plus I spelled "note" as "not". :-P