我可以使用 python 以二进制模式打开文件
open ('filename', 'rb') as f:
for line in f:
print line
如何在 Node 中执行此操作?
input = fs.createReadStream filePath, {flags: "rb"}
无论如何,这是错误的
最佳答案
If no encoding is specified, then the raw buffer is returned.
fs.readFile(file[, options], callback)
fs.readFile('filename', (err, buffer) => {
if (err) throw err;
console.log(`${buffer}: ${buffer.length} characters, ` +
`${Buffer.byteLength(buffer, 'utf8')} bytes`);
});
The Buffer class is a global type for dealing with binary data directly. It can be constructed in a variety of ways.
关于node.js - nodejs以二进制模式创建readstream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34761465/