Skip to content

Instantly share code, notes, and snippets.

View elisee's full-sized avatar
🐊

Elisée Maurer elisee

🐊
View GitHub Profile
@elisee
elisee / BinaryReader.coffee
Created May 14, 2013 23:35
Read binary data written with .NET's BinaryWriter in CoffeeScript / JavaScript. Simply pass an ArrayBuffer to the constructor and then call the Read* methods.
class CSPlayer.BinaryReader
if TextDecoder?
# The TextDecoder API properly decodes UTF-8
textDecoder = new TextDecoder()
@DecodeString = (array) -> textDecoder.decode array
else
# If the TextDecoder API isn't available, fall back to ASCII decoding
@DecodeString = (array) -> String.fromCharCode.apply null, array
constructor: (buffer) ->