encoding for non-utf8 text?
demon386 opened this issue · 2 comments
Related to: atom/git-diff#60
My file is GBK encoded. The problem is that for GBK encoded lines, getLineDiffs
signals diffs on those lines, even nothing at all is changed.
I tried to use iconv-lite to encode the text to 'GBK' and then decode to 'utf-8' before passing text to getLineDiffs
, the problem still exists.
git-diff uses the following way to invoke getLineDiffs
:
getLineDiffs(path, @editor.getText())
When the file is GBK encoded, whether open with UTF-8 or GBK encoding in Atom, pseudo diffs on those GBK lines exist.
Of course, for GBK encoded file one should open it with GBK encoding in Atom (the above UTF-8 is just for debugging). When opening with GBK encoding, I tried to use iconv-lite to encode text:
buffer = iconv.encode(@editor.getText(), 'gbk')
getLineDiffs(path, iconv.decode(buffer, 'utf-8'))
I also tried
buffer = iconv.encode(@editor.getText(), 'gbk')
getLineDiffs(path, buffer.toString())
and
buffer = iconv.encode(@editor.getText(), 'gbk')
getLineDiffs(path, buffer.toString('utf-8'))
None of these work.
This issue is a duplicate of atom/atom#18224 or atom/git-diff#60