Howard Bullock
(KiX Supporter)
2002-11-17 11:23 PM
Binmode file access

New feature request: Binmode Reading and Writing.

LonkeroAdministrator
(KiX Master Guru)
2002-11-17 11:24 PM
Re: Binmode file access

me want too.

ShawnAdministrator
(KiX Supporter)
2002-11-17 11:30 PM
Re: Binmode file access

me want three

Will Hetrick
(Hey THIS is FUN)
2002-11-18 04:52 PM
Re: Binmode file access

I will take binmode reading and writing for Number 4.

Sealeopard
(KiX Master)
2002-11-18 07:59 PM
Re: Binmode file access

I'll take BINMODE READING for 400 and got a joker [Wink]

ShawnAdministrator
(KiX Supporter)
2002-11-18 08:13 PM
Re: Binmode file access

I'll take Current Events for 1000, Alex.

And the answer is: BIN READING

What has Osama bin doing for the past 12 months, squirreled away in his mountain retreat.

lol


Howard Bullock
(KiX Supporter)
2002-11-18 08:18 PM
Re: Binmode file access

[Big Grin] [Big Grin] I liked that one. ROTFLMAO

Will Hetrick
(Hey THIS is FUN)
2002-11-18 08:23 PM
Re: Binmode file access

ROFL. Good one Shawn!

Radimus
(KiX Supporter)
2002-11-18 08:33 PM
Re: Binmode file access

Bin Running
Bin Hiding
Bin Ducking
Bin Dodging


Sealeopard
(KiX Master)
2002-11-18 08:36 PM
Re: Binmode file access

Bin Writing
Bin Sending
Bin Downgrading
Bin Daytrading


Les
(KiX Master)
2002-11-18 08:52 PM
Re: Binmode file access

let's please try and remain professional in the Suggestions forum. We do of course, want Ruud to take us seriously.

Howard Bullock
(KiX Supporter)
2002-11-18 09:02 PM
Re: Binmode file access

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 ]


Richard H.Administrator
(KiX Supporter)
2002-11-19 10:49 AM
Re: Binmode file access

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 [Wink] )

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.


NTDOCAdministrator
(KiX Master)
2004-11-26 10:19 AM
Re: Binmode file access

Some good thoughts and ideas Richard, but sort of sounding more like a Binary Editor rather then a script processor.

Personally have had very little need to modify too many binary files with a script, but I do see where the use of supporting NULLS has come up for me and any many posts on the board. Supporting binary mode would include this, so thus I agree we need some sort of support.

Hopefully Ruud reads all these suggestion posts and can give some feedback as well some time.


LonkeroAdministrator
(KiX Master Guru)
2004-11-26 10:53 AM
Re: Binmode file access

script processor?
script processor processes scripts given to it.
doesn't matter does the script processor support binary editing or not, it still is script processor as long as it does process the scripts.
see?


NTDOCAdministrator
(KiX Master)
2004-11-26 11:00 AM
Re: Binmode file access

This isn't English 101 don't get so caught up in names Jooel.

Richard H.Administrator
(KiX Supporter)
2004-11-26 11:26 AM
Re: Binmode file access

I've recently posted a solution for reading and writing binary data using KiXtart elsewhere on the board - including NULLs.

NTDOCAdministrator
(KiX Master)
2004-11-26 11:35 AM
Re: Binmode file access

Hi Richard, do you have a link to that post?

LonkeroAdministrator
(KiX Master Guru)
2004-11-26 11:39 AM
Re: Binmode file access

doc, sure this isn't.
but you need to understand my point.
what you think script processor (or kixtart) should be like, may not fit to anybody elses ideas.
or...
anyway, I think you get my point.



Richard H.Administrator
(KiX Supporter)
2004-11-26 11:45 AM
Re: Binmode file access

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.