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
FinTech SaaS Company for Financial Institutions; Interview With Justin Fischer, The CEO of RiskScout.
This fintech-focused VC firm just closed a $75 million debut fund; backers 'came out of the woodwork' | TechCrunch
Toa Guide Osrs
Best Pizza Novato
Dollywood's Smoky Mountain Christmas - Pigeon Forge, TN
Ret Paladin Phase 2 Bis Wotlk
Jeremy Corbell Twitter
Comforting Nectar Bee Swarm
Driving Directions To Fedex
How Much Is 10000 Nickels
What Auto Parts Stores Are Open
Mustangps.instructure
Displays settings on Mac
King Fields Mortuary
Cosentyx® 75 mg Injektionslösung in einer Fertigspritze - PatientenInfo-Service
ds. J.C. van Trigt - Lukas 23:42-43 - Preekaantekeningen
How to Watch Braves vs. Dodgers: TV Channel & Live Stream - September 15
The Haunted Drury Hotels of San Antonio’s Riverwalk
My Vidant Chart
Becky Hudson Free
Gina's Pizza Port Charlotte Fl
Aquatic Pets And Reptiles Photos
Persona 4 Golden Taotie Fusion Calculator
Identogo Brunswick Ga
Red Tomatoes Farmers Market Menu
Is Grande Internet Down In My Area
Danforth's Port Jefferson
Ratchet & Clank Future: Tools of Destruction
Pjs Obits
Catherine Christiane Cruz
Teen Vogue Video Series
Tips and Walkthrough: Candy Crush Level 9795
What Time Does Walmart Auto Center Open
Haunted Mansion Showtimes Near Epic Theatres Of West Volusia
Bay Area Craigslist Cars For Sale By Owner
Hefkervelt Blog
Gopher Hockey Forum
Fbsm Greenville Sc
Lehpiht Shop
Craigslist Albany Ny Garage Sales
Facebook Marketplace Marrero La
Umiami Sorority Rankings
Skyrim:Elder Knowledge - The Unofficial Elder Scrolls Pages (UESP)
Craigslist Ludington Michigan
Kornerstone Funeral Tulia
Dr Mayy Deadrick Paradise Valley
Thotsbook Com
Craigslist/Nashville
Devotion Showtimes Near Showplace Icon At Valley Fair
Walmart Front Door Wreaths
Denys Davydov - Wikitia
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.