gpt4 book ai didi

node.js - 我应该使用哪个 nodejs 库来写入 HDFS?

转载 作者:可可西里 更新时间:2023-11-01 14:14:27 24 4
gpt4 key购买 nike

我有一个 nodejs 应用程序,我想将数据写入 hadoop HDFS 文件系统。我见过两个主要的 nodejs 库可以做到这一点:node-hdfs 和 node-webhdfs。有人试过吗?有什么提示吗?我应该在生产中使用哪一个?

我倾向于使用 node-webhdfs,因为它使用 WebHDFS REST API。 node-hdfs 似乎是一个 c++ 绑定(bind)。

任何帮助将不胜感激。

最佳答案

您可能想查看 webhdfs图书馆。它为 WebHDFS REST API 调用提供了漂亮而直接的(类似于 fs 模块 API)接口(interface)。

写入远程文件:

var WebHDFS = require('webhdfs');
var hdfs = WebHDFS.createClient();

var localFileStream = fs.createReadStream('/path/to/local/file');
var remoteFileStream = hdfs.createWriteStream('/path/to/remote/file');

localFileStream.pipe(remoteFileStream);

remoteFileStream.on('error', function onError (err) {
// Do something with the error
});

remoteFileStream.on('finish', function onFinish () {
// Upload is done
});

从远程文件读取:

var WebHDFS = require('webhdfs');
var hdfs = WebHDFS.createClient();

var remoteFileStream = hdfs.createReadStream('/path/to/remote/file');

remoteFileStream.on('error', function onError (err) {
// Do something with the error
});

remoteFileStream.on('data', function onChunk (chunk) {
// Do something with the data chunk
});

remoteFileStream.on('finish', function onFinish () {
// Upload is done
});

关于node.js - 我应该使用哪个 nodejs 库来写入 HDFS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20929000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com