Created
May 26, 2017 02:19
-
-
Save xuyuji9000/6a6b6ef46370cbe08790b4b789eaf68a to your computer and use it in GitHub Desktop.
JS string encoding convert, with iconv-lite and jschardet.
This file contains 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
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