Commit 7e290660 authored by Ryan LeFevre's avatar Ryan LeFevre

Use iconv for proper character decoding

parent e63bf76d
{jspack} = require 'jspack' {jspack} = require 'jspack'
iconv = require 'iconv-lite'
Util = require './util.coffee' Util = require './util.coffee'
module.exports = class File module.exports = class File
...@@ -41,10 +42,8 @@ module.exports = class File ...@@ -41,10 +42,8 @@ module.exports = class File
readString: (length) -> String.fromCharCode.apply(null, @read(length)).replace /\u0000/g, "" readString: (length) -> String.fromCharCode.apply(null, @read(length)).replace /\u0000/g, ""
readUnicodeString: (length = null) -> readUnicodeString: (length = null) ->
length or= @readInt() length or= @readInt()
@read(length * 2) data = new Buffer(@read(length * 2))
.map((c) -> Util.getUnicodeCharacter(c)) iconv.decode(data, 'utf-16be')
.join('')
.replace(/\u0000/g, '')
readByte: -> @read(1)[0] readByte: -> @read(1)[0]
readBoolean: -> @readByte() isnt 0 readBoolean: -> @readByte() isnt 0
\ No newline at end of file
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
"coffeescript-module": "~ 0.2.1", "coffeescript-module": "~ 0.2.1",
"pngjs": "~ 0.4.0", "pngjs": "~ 0.4.0",
"rsvp": "~ 3.0.6", "rsvp": "~ 3.0.6",
"lodash": "~ 2.4" "lodash": "~ 2.4",
"iconv-lite": "~ 0.4.4"
}, },
"scripts": { "scripts": {
"test": "mocha test" "test": "mocha test"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment