#120637 - 2004-06-04 04:25 PM
RFC: binary file access, byte format
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
if you would have a way to read binary files, unicode files and so on with kixtart, how would you like your file appear to you?
say, you have textfile with context of: blaah
so, would you like it as array of integers: $file=98,97,97,104
or, array of hex-values: $file=62,61,61,68
or, as array of binary: $file="1100010","1100001","1100001","1101000"
yet one more option would be binaryString: $file="01100010011000010110000101101000"
the reason for the request is, that there is ability to do this. but before doing it, the format of output is pretty crucial. for text files, the integer way is the the fastest (like for others, afaik) and most suitable (as it's the same as asc() all the chars) and does require the least modification before manipulation.
so, asking for personal opinions for those who might want some more advanced file access.
_________________________
!download KiXnet
|
Top
|
|
|
|
#120640 - 2004-06-04 05:28 PM
Re: RFC: binary file access, byte format
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If you are going to add binary file access, don't forget "seek()" to skip to a specific byte in the file, and "trunc[ate]()" when writing to delete the end of a file.
Also, it would be nice to be able to read/write simple strings when you know the the data is not going to contain hard to handle characters. In this case you will need to be able to specify the number of characters to read.
How about presenting the file as a stream, and just return the characters, something like: Code:
If OpenBinary(1,"somefile.doc","r") "Could not open file for reading!"+@CRLF Else $c=ReadChar(1) While @ERROR=0 "Got character #"+CStr($c)+@CRLF $c=ReadChar(1) Loop EndIf
This way it kind of follows the existing command syntax.
|
Top
|
|
|
|
#120649 - 2004-06-06 03:05 AM
Re: RFC: binary file access, byte format
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
k, I currently have working object for reading and writing data. succesfully stored an jpg as kixtart array in file... doh, so bloody happy I got it finally done. now I can start testing using it with ntbackup bks'es
anyway, if someone would like it (not so usefull maybe yet), I have it.
the methods include only read & write: Code:
$obj=createobject("kixbin.file") ;opens file, reads it, closes it and returns the bytes as array of ints $arrayTOstoreTHEdataIN = $obj.read($FilePath) ;opens file, writes the given data to it and closes it. if file exists, deletes context first $obj.write(FileToWrite,$arrayOFdataToWrite)
well, the error part is still obviously missing. so is switch for append. and so on...
_________________________
!download KiXnet
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 316 anonymous users online.
|
|
|