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

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
keithglong
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 348
Joined: Sun Jul 03, 2011 2:04 am

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

Post by keithglong » Fri Jul 22, 2011 10:34 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

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

Post by Mark » Sat Jul 23, 2011 12:19 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

keithglong
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 348
Joined: Sun Jul 03, 2011 2:04 am

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

Post by keithglong » Sat Jul 23, 2011 12:29 am

Thanks! I am continuing to experiment--and things are becoming more clear...

Post Reply