Skip to content

Instantly share code, notes, and snippets.

@meltingice
Created March 14, 2012 16:50
Show Gist options
  • Save meltingice/2037813 to your computer and use it in GitHub Desktop.
Save meltingice/2037813 to your computer and use it in GitHub Desktop.
Example port of Ruby's BinData to Coffeescript
class Rectangle extends BinData.Record
endian: "little"
parse: ->
uint16 "len"
string "name", readLength: len
uint32 "width"
uint32 "height"
r = new Rectangle(file)
console.log "Rectangle #{r.name} is #{r.width} x #{r.height}"
@kellysutton
Copy link

Nice. Now it just needs a data source.

@meltingice
Copy link
Author

Oh, duh. I could probably pair it with a simplified version of my PSDFile class.

@kellysutton
Copy link

Yeah, I ended up creating a "data" class for some of the resources. Here's mine for the header:

class PSDHeaderData < BinData::Record
  ">4sH 6B HLLHH"
  endian  :big
  string  :signature, :read_length => 4
  uint16  :version
  uint8   :a
  uint8   :b
  uint8   :c
  uint8   :d
  uint8   :e
  uint8   :f
  uint16  :channels
  uint32  :rows
  uint32  :cols
  uint16  :depth
  uint16  :mode
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment