1

How can I read a structured data file in Julia?

Speaking in python, if I have defined some c-styled format:

df = [
['Label',    '4s'],
['Version',   'i'],
['Revision',   'i'],
['Date',      '28s'],
['FileFormat', '2i'],
['FileType',   '4s'],
['OriginalFileName', '68s'],   ...etc]

df is parsed out into var_names and structure and then read:

fh = open(fn,'rb')
data = fh.read()
header = struct.unpack_from(struct_format, data[0:structsize])

I can't figure out how to do something equivalent in Julia.

In a somewhat similar question, I see how I could build a type to handle this but have yet to figure out how a variable can have a specific amount of base types; 4 ints for example.

I've read all the documentation I can find on sprint and its cousins, but haven't found any examples to help make sense of the them.

vhu
  • 12,244
  • 11
  • 38
  • 48

1 Answers1

1

It's possible that StrPack.jl will do some or all of what you want. I think the documentation emphasizes its use for in-memory objects, but its original purpose was to handle this problem. Might be worth browsing the source and perhaps contributing patches.

tholy
  • 11,882
  • 1
  • 29
  • 42