#81339 - 2002-11-17 11:23 PM
Binmode file access
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
New feature request: Binmode Reading and Writing.
|
Top
|
|
|
|
#81345 - 2002-11-18 08:18 PM
Re: Binmode file access
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I liked that one. ROTFLMAO
|
Top
|
|
|
|
#81347 - 2002-11-18 08:33 PM
Re: Binmode file access
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Bin Running Bin Hiding Bin Ducking Bin Dodging
|
Top
|
|
|
|
#81350 - 2002-11-18 09:02 PM
Re: Binmode file access
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If we don't give him bbChecker, he'll have to start at the beginning of the thread while it was still serious...Maybe the point will be made by the time he makes it half way down. [ 18. November 2002, 21:04: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#81351 - 2002-11-19 10:49 AM
Re: Binmode file access
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
How do you guys see the binary I/O working?
Personally I'd like to see an extension to KiXtart which includes binary data types which would be used for other things like information returned by COM objects and the like.
Another (far simpler) approach would be to provide some new file functions that use a buffer. The buffer is an array in which each element is the ASCII value of the character which has been read/will be written.
The functions would take the form:
code:
$iBytesRead=ReadArray($fdFileDescriptor,$aiDataRead,$iBytesToRead)
$iBytesRead is the number of bytes successfully read, "0" if there is no more data (end of file) and "-1" if there is an error. $fdFileDescriptor is the file number used in the file Open(). $aiDataRead is the array which will contain the values of the data read. $iBytesToRead is the number of bytes that you want to read - could be optional in which case it is the size of the array.
Similarly the write would be:
code:
$iBytesWritten=WriteArray($fdFileDescriptor,$aiWriteData,$iBytesToWrite
The wide awake among you will have spotted a problem with ReadArray(). The array is passed as a parameter. To be able to populate the array with the data, we would need pass-by-reference support in KiXtart, and we don't. Yet.
So, ReadArray can be simplified to:
code:
$aiDataRead=ReadArray($fdFileDescriptor,$iBytesToRead)
@ERROR can be checked for end-of-file and error conditions. The number of bytes read is the size of the array. I prefer the first method as there is a small problem with this way of doing reads in that it is tricky to identify when some data was read before an error occurred.
The other change required is that the Open() function will probably need a flag to ensure that the file is opened in binary or "raw" mode. This is because it will probably be required by the underlying file open API.
Mixing binary and non-binary reads and writes may be possible, but the results will be hard to predict and should be avoided.
Performing binary reads and writes on a file not opened in binary mode (and vice versa) will also have unexpected results.
Some more thoughts (shouldn't think and type at the same time )
If binary file I/O is implemented it should be able to support random file I/O, i.e.:
- A file can be opened for both read and write.
- Seek() function to move the file cursor to an arbitrary location in the file (1=start, -1=end)
- Truncate() function to reduce the size of the file (when you've deleted data from the end) or to initialize a file which has data in it already that you want to discard
We would also need some way of dealing with non-string data, WriteInteger(), ReadFloat() perhaps? Or maybe a way of converting the data types to a character array for reading/writing. Other useful support functions would allow filling an array with a character, padding a string to a length with an arbitrary character and split()/join() to work with a null delimiter.
The more I think about it the more complex it gets.
Enough of my ramblings, for now.
|
Top
|
|
|
|
#81358 - 2004-11-26 11:45 AM
Re: Binmode file access
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Hi Richard, do you have a link to that post?
Here you go.
The routines in the link convert to/from "byte array" format which you can use directly with ADODB.stream to read and write binary files.
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 370 anonymous users online.
|
|
|