Page 1 of 1 1
Topic Options
#120637 - 2004-06-04 04:25 PM RFC: binary file access, byte format
Lonkero Administrator Offline
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
#120638 - 2004-06-04 04:40 PM Re: RFC: binary file access, byte format
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Having the values as binary or hex in the array doesn't add any value. You are more likely to require the decimal value.

Having the values as a string further complicate things.

My vote is for an array of decimal integers.

Top
#120639 - 2004-06-04 05:03 PM Re: RFC: binary file access, byte format
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I hoped for that vote as binaryString made it rather complicated.
got it done but for reading 50k image took around 30s to read because all the overheat.

I might add some param for choice in here but indeed, ints look the best to me.
_________________________
!

download KiXnet

Top
#120640 - 2004-06-04 05:28 PM Re: RFC: binary file access, byte format
Richard H. Administrator Offline
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
#120641 - 2004-06-04 06:56 PM Re: RFC: binary file access, byte format
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
heh, the way you wrote it, it would require it to be inbuild or done via UDF's.

anyways, was thinking more of:
$file=readfile("fullpath")

that would be the easiest way to do.
on the other hand, it might get little harder (and slower) playing with the data in kixtart.
_________________________
!

download KiXnet

Top
#120642 - 2004-06-05 04:43 AM Re: RFC: binary file access, byte format
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
damn, started thinking...
with unicode files, a char is 2 bytes, right?
so, instead of say 0 you get 0 0.

is that acceptable?
_________________________
!

download KiXnet

Top
#120643 - 2004-06-05 03:24 PM Re: RFC: binary file access, byte format
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
I'd go with a Byte-Array fo ASCII-codes, e.g. a 4-byte string would be represented as
Code:

$string[0]=0
$string[1]=5
$string[3]=10
$string[4]=55
$

_________________________
There are two types of vessels, submarines and targets.

Top
#120644 - 2004-06-05 04:15 PM Re: RFC: binary file access, byte format
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
My vote is definitely an array of numbers (from 0 to 255) ... since Kixtart only uses LONGS, the unused bits just get left as unused.
Top
#120645 - 2004-06-05 04:58 PM Re: RFC: binary file access, byte format
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm, I've used byte ints with success, so kixtart surely supports them (at least when it reads them) not sure about the writing.
anyway, this is the problem I'm currently facing and once you shawn have slept some, you gonna be my info-bank
_________________________
!

download KiXnet

Top
#120646 - 2004-06-05 05:18 PM Re: RFC: binary file access, byte format
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I can lend some advise with the COM safe arrays if thats what you mean. ja - I was thinking you could read the file in either text-mode or binary-mode. Text mode is pretty straight-forward, binary mode you would need to do some homework. Might try returning a variant array of uchars or bytes or the like, not sure if Kixtart can handle it. If it did would probably just convert it to a variant array of longs anyways. Then when your write the binary data back, your stuff would probably need to convert each long back to byte. If Kixtart can handle a variant array of bytes then all is good.
Top
#120647 - 2004-06-05 06:00 PM Re: RFC: binary file access, byte format
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, the reading part is working.
kixtart handles my "file-array" as it was kixtart's own.

doing simple:
$file=$object.read("myfile")
$file[4]

returns the fifth byte from the file as long.
_________________________
!

download KiXnet

Top
#120648 - 2004-06-05 06:03 PM Re: RFC: binary file access, byte format
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
anyways, next problem is to get errors working
tried to get them out but you know, I'm not so good at error handling
_________________________
!

download KiXnet

Top
#120649 - 2004-06-06 03:05 AM Re: RFC: binary file access, byte format
Lonkero Administrator Offline
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
#120650 - 2004-06-06 03:29 AM Re: RFC: binary file access, byte format
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, decided to put it out for those who fancy testing:
http://www.gwspikval.com/jooel/files/KiXbin/
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 316 anonymous users online.
Newest Members
SERoyalty, mytar, Gabriel, Alex_Evos, Dansen
17869 Registered Users

Generated in 0.069 seconds in which 0.025 seconds were spent on a total of 14 queries. Zlib compression enabled.

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