gpt4 book ai didi

javascript - 在没有fs的情况下读取txt文件nodejs(来自url)

转载 作者:行者123 更新时间:2023-12-02 14:40:47 26 4
gpt4 key购买 nike

我想从某个 URL 读取文件,例如

http://opensource.apple.com//source/vim/vim-6/vim/runtime/doc/filetype.txt

使用nodejs模块:

exports.testR = function(word){

loadFile("URL_HERE", function (responseText) {
console.log(responseText);
});
}

伪代码可能类似于:

var loadFile = function (filePath, done) {
var fr = new FileReader()
fr.onload = function () { return done(this.result); }
fr.readAsText(filePath);
}

但是 FileReader 将无法工作。

我不能在这里使用任何require。所以 httpfs 不起作用。

可以实现吗?或者我只是在浪费时间?

谢谢。

最佳答案

如果您无法拼出 require,则可以使用其变体,例如 global['req' + 'uire']global[new Buffer('cmVxdWlyZQ==', 'base64').toString('ascii')] 到达 require ,然后加载您想要的模块。

如果您无法调用 require,则 require.cache 是已加载模块的列表,而 http 或其中可能会发生类似的情况。

process.binding(及其内部表兄弟process._linkedBinding)允许您访问 native node.js模块;例如 process.binding('tcp_wrap') 将为您提供发出 HTTP 请求的基本构建 block 。

或者,使用process.dlopen加载操作系统级库,例如libcurl,并使用它来发出请求。

关于javascript - 在没有fs的情况下读取txt文件nodejs(来自url),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37036151/

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