Created
March 14, 2012 16:50
-
-
Save meltingice/2037813 to your computer and use it in GitHub Desktop.
Example port of Ruby's BinData to Coffeescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
Oh, duh. I could probably pair it with a simplified version of my PSDFile class.
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
Nice. Now it just needs a data source.