Page 1 of 1 1
Topic Options
#147382 - 2005-09-08 07:06 PM enhance readline() to return the whole buffer at once
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
... or make a readfile() command for it.

instead of looping after the update one could simply use:
$myFile=readline(1,1)

to return the whole file at once.
_________________________
!

download KiXnet

Top
#147383 - 2005-09-09 09:56 AM Re: enhance readline() to return the whole buffer at once
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I'd prefer raw file i/o as a solution something like
Code:

$fdFile=fOpen("c:\temp\file.txt",2+8) ; Open for reading (in binary mode)
$=fSeek($fdFile,-1) ; Fast forward to end of file
$lFileSize=fTell($fdFile) ; How big is file?
$=fRewind($fdFile) ; Back to start of file
$FileData=fRead($fdFile,$lFileSize) ; Read entire file into buffer


Top
#147384 - 2005-09-09 10:51 AM Re: enhance readline() to return the whole buffer at once
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, I would too.
but raw I/O is not gonna happen.

I mean, as far as we know, it's not even on the todo-list.
_________________________
!

download KiXnet

Top
#147385 - 2005-09-28 01:19 AM Re: enhance readline() to return the whole buffer at once
iffy Offline
Starting to like KiXtart

Registered: 2005-05-29
Posts: 149
Loc: The Netherlands
Hey, I want this raw I/O stuff too, I've had to use kludges to get around the lack of support binary reads and seeks.. And make the fRead with a 3rd parameter specificing the size of the buffer in case you only want xxx bytes from the seek point. Please... pretty please
Top
#147386 - 2005-09-28 03:56 AM Re: enhance readline() to return the whole buffer at once
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
What do you guys think about having the flexibility of setting the end-of-line character for READLINE? That way we could have a great deal of flexibility in reading partial or complete files into a variable. We could set the line separator to "" and read the entire file. Or we could set the EOL value to some other value to split lines during the READLINE.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#147387 - 2005-09-28 10:24 AM Re: enhance readline() to return the whole buffer at once
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Tricky.

You can't get some characters into strings, so it wouldn't work in all cases. A common string delimiter in file data is Chr(0), and you can't get that into a string to supply as a parameter. You could pass just the numeric value I guess, but that would make passing multi-character delimitors difficult. To be useful you'd probably want to have multiple alternate values - space, tab, CR and LF are the most obvious selection.

If would be nice to be able to differentiate between CRLF and CR delimited files though.

Top
#147388 - 2005-09-28 10:29 AM Re: enhance readline() to return the whole buffer at once
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

And make the fRead with a 3rd parameter specificing the size of the buffer in case you only want xxx bytes from the seek point. Please... pretty please




No need for a third parameter.

The second parameter in the pseudo-code is the buffer size. As this topic is about reading the entire file I set the read size to the size of the file in the example, but it could be any value.

Top
#147389 - 2005-09-28 02:01 PM Re: enhance readline() to return the whole buffer at once
iffy Offline
Starting to like KiXtart

Registered: 2005-05-29
Posts: 149
Loc: The Netherlands
And if you are going to enhance do it right so I suggested not to limit yourself to only read the entire file but optionally specify a buffer in case you only want a part of a (binary) file. A standard function in most other languages.
Top
#147390 - 2005-09-28 03:07 PM Re: enhance readline() to return the whole buffer at once
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

And if you are going to enhance do it right so I suggested not to limit yourself to only read the entire file but optionally specify a buffer in case you only want a part of a (binary) file. A standard function in most other languages.




At the risk of my repeating myself that is exactly what it does.

Re-read the pseudo-code, and if you still don't understand how it does partial file reads send me a PM and I'll explain off-line.

Top
#147391 - 2005-09-28 08:56 PM Re: enhance readline() to return the whole buffer at once
iffy Offline
Starting to like KiXtart

Registered: 2005-05-29
Posts: 149
Loc: The Netherlands
You're right of course Richard, ignore my previous babbling. I completely misread the pseudo code for some reason.
Top
#147392 - 2005-09-28 09:20 PM Re: enhance readline() to return the whole buffer at once
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, there are 2 totally different suggestions and I think iffy was flying on the wings of the original one where Richie took it a bit further.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 414 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.058 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org