How Do I Process a Binary File? | How To - Step-By-Step Guides To Tasks In LiveCode (2024)

This lesson will show you how to open a binary file, process binary data and write binary data to a file.

Reading a Binary File Into LiveCode

When loading data into LiveCode from a file you have two options - load the data as text or load the data as binary. Loading file data as binary means that the LiveCode engine will load the data as-is, without converting any line feeds or return characters. The same holds true when writing a file to disk as well.

You can choose one of two methods for loading the data.

1) Use the commands open file, read from file and close file.

put "/path/to/myimage.png" into theFilePathopen file theFilepath for binary readread from file theFilePath until endput it into theBinaryDataclose file theFilePath

2) Use the URL keyword with the put command, prefixing the file path with "binfile:".

put "/path/to/myimage.png" into theFilePathput URL ("binfile:" & theFilePath) into theBinaryData

Either approach allows you to place binary data into a variable so that it can be processed.

Accessing Bytes In Binary Data

With LiveCode you can access individual bytes in binary data by using the byte chunk. For example, if I want to access byte 8 in some binary data I could do the following:

## Assume that binary data is stored in the variable theBinaryDataput byte 8 of theBinaryData into theByte## Loop through all bytes in datarepeat for each byte theByte in theBinaryData-- process theByte here (but don't modify directly)end repeat

Decoding Binary Data

LiveCode also allows you to decode binary data into various formats using the binaryDecode function. For example, if you wanted to decode the 8-byte signature of PNG data into hexadecimal digits you could do the following:

## Assume the variable thePNGData already has PNG data stored in it.## Convert first 8 bytes to hexadecimal digitsput binarydecode("H16", thePNGData, theSignature) into theNumConversions## The variable theSignature now contains '89504e470d0a1a0a' if theSignature contains valid data.put theSignature

Writing a Binary File From LiveCode

Writing data from LiveCode to a file is the same as loading the data - you must explicitly tell the LiveCode engine that you want to write the data as binary data.

You can choose one of two methods for writing the data.

1) Use the commands open file, write to file and close file.

put "/path/to/myimage.png" into theFilePathopen file theFilepath for binary write ## you might also use 'binary update' here to modify part of filewrite theBinaryData to file theFilePathclose file theFilePath

2) Use the URL keyword with the put command, prefixing the file path with "binfile:".

put "/path/to/myimage.png" into theFilePathput theBinaryData into URL ("binfile:" & theFilePath)

Either approach allows you to write binary data to a file. One difference to be aware of is that open file allows you the option of updating part of a file while the put form does not.

How Do I Process a Binary File? | How To - Step-By-Step Guides To Tasks In LiveCode (2024)
Top Articles
Cash Flow Forecasting Template
Mining and Mineral Processing
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Selly Medaline
Latest Posts
Article information

Author: Pres. Carey Rath

Last Updated:

Views: 5967

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.