Page 1 of 1

Is it possible to write to and from a binary file?

Posted: Fri Jul 22, 2011 10:34 pm
by keithglong
Hello All,

I am new to LiveCode and am continuing to explore the language. 8-)

Quick question... Is it possible to write to and from a binary file utilizing LiveCode? For example, is it possible to take a graphic file (for example) and split it into several unequal parts, and then put the parts back together again into a single file? I have used another programming package to accomplish such.

FYI: Reading in the Dictionary, I came across the byte and binfile entries. Can these be used to accomplish what I am looking for? If so, then are there any good examples out there?

Thanks, and any help is most appreciated!

Cheers from Florida!

- Boo

Re: Is it possible to write to and from a binary file?

Posted: Sat Jul 23, 2011 12:19 am
by Mark
Hi Keith,

This is standard stuff.

Code: Select all

on example
  answer file "Select a binary file..."
  if it is not empty then
    put it into myFile
    open file myFile for binary read
    read from file myFile until EOF
    put it into myData
    close file myFile
    // do something with the data below this line
  end if
end example
Instead of open, read, close you can also use:

put url ("binfile:" & myFile) into myData

Open/read/close gives you more control, but put url seems more straightforward (and less lines)

(this is a copy of my reply to the LiveCode use list)

Kind regards,

Mark

Re: Is it possible to write to and from a binary file?

Posted: Sat Jul 23, 2011 12:29 am
by keithglong
Thanks! I am continuing to experiment--and things are becoming more clear...