node.js - NodeJS 扩展的 ASCII 支持

标签 node.js encoding ascii

我正在尝试读取一个包含扩展 ASCII 字符(如“á”或“è”)的文件,但 NodeJS 似乎无法识别它们。

我试着阅读:

  • 缓冲区
  • 字符串

尝试了不同的编码类型:

  • ASCII
  • base64
  • utf8

引用 http://nodejs.org/api/fs.html

有没有办法让它工作?

最佳答案

我使用二进制类型读取此类文件。例如

var fs = require('fs');

// this comment has I'm trying to read a file that contains extended ascii characters like 'á' or 'è',

fs.readFile("foo.js", "binary", function zz2(err, file) {  
    console.log(file);
});

当我将以上内容保存到 foo.js 中时,输出中将显示以下内容:

var fs = require('fs');

// this comment has I'm trying to read a file that contains extended ascii characters like '⟡ 漀爀 ✀',

fs.readFile("foo.js", "binary", function zz2(err, file) {  
    console.log(file);
});

上面的奇怪是因为我在 emacs 缓冲区中运行它。

关于node.js - NodeJS 扩展的 ASCII 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11528722/

相关文章:

node.js - 如何从 Redis 存储客户端的键/值对中的值中获取键?

c++ - 音频MP2编解码产生半数据C++和FFMPEG

转换 a-z 以打印出 abcdef....z?

c++ - 如何将整数转换为其等效的 ascii

javascript - 获得帖子 react 的空列表。可能是什么原因?

node.js - 如何使用 monk 使用 Node.js 启动 mongodb

node.js - "Cannot read property ' 在 Npm 安装期间匹配 ' of undefined"

python-2.7 - 不同的 unicode 处理 python2.7.9 与 2.7.15

java - Java 的 String.GetBytes(Charset) 中的 UTF-8

java - Java 上的文件中的某些字符读取为问号 (?)