• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reading a binary file format?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading a binary file format?


  • Subject: Re: Reading a binary file format?
  • From: Robert Martin <email@hidden>
  • Date: Fri, 12 Oct 2007 13:33:25 -0400

I wrote a set of Cocoa classes that parse out binary or ascii files based on a file/record structure that you define in XML using a fairly small but powerful 'grammar'. The results for sections of 'records/fields' that you define are handed back to you in a dictionary (or an array of dictionaries if you define 'repeat' sections).

It also has a small 'test' app that lets you muck about with the XML rules on-the-fly, so you get immediate feedback on where to tweak the structure definition.

It handles endian-ness, integer types and doubles, padding, searching for starts/ends/boundaries via strings or character sets, number arrays, plain strings, skipping etc - and uses the standard C lib calls.

If you want to give it a whirl, let me know (probably OT, so direct mail). I was thinking about sprucing it up for anyone to download, but haven't got around to writing 'release quality' documentation yet.

Rob


On Oct 12, 2007, at 9:50 AM, Stephen Hoffman wrote:


Keith Blount wrote:
I need to read what I assume is a binary file into my
program. I know where to expect the various parts of
the file, I'm just not sure how to read them in -
probably because I'm self-taught at Cocoa (Kochan &
Hillegass) and it requires a lower level of C, I'm not
sure.

<snips...>

To poke around inside the file itself, use the shell od (octal dump) or hexdump commands. This will show you the bytes and byte counts, from which the underlying structures can often be discerned.


In summary, there are a whole pile of different ways to write a binary file in C. I'd not expect to be able to read a random C data file directly in Cocoa without using some C code; without going into more effort than reading it using C and converting the fields and (I assume) records over into Cocoa structures as each is read in.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Reading a binary file format? (From: Stephen Hoffman <email@hidden>)

  • Prev by Date: WebView - intercepting data before load
  • Next by Date: RE: Memory leaks when running an apple event
  • Previous by thread: Re: Reading a binary file format?
  • Next by thread: Highlighting NSView used in NSStatusItem
  • Index(es):
    • Date
    • Thread