Skip to content

Instantly share code, notes, and snippets.

@xuyuji9000
Created May 26, 2017 02:19
Show Gist options
  • Save xuyuji9000/6a6b6ef46370cbe08790b4b789eaf68a to your computer and use it in GitHub Desktop.
Save xuyuji9000/6a6b6ef46370cbe08790b4b789eaf68a to your computer and use it in GitHub Desktop.
JS string encoding convert, with iconv-lite and jschardet.
const reader = new FileReader()
const file = this.uploadInput.files[0]
let self = this
reader.onload = function()
{
let target_data = ''
const data_info = jschardet.detect(reader.result)
if('ascii'==data_info.encoding && data_info.confidence > 0)
target_data = this.result
else
target_data = iconv.decode(Buffer.from(this.result, 'binary'), 'GB18030')
})
}
reader.readAsText(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment