javascript - 从大文件流式传输并创建数组

标签 javascript node.js highland.js

我在使用 highland.js 时遇到问题。我需要从我的流数据创建一个函数数组,但无法让它工作。这是我的代码,但是 requests 始终为空。

var requests = [];           
_(fs.createReadStream("small.txt", { encoding: 'utf8' }))
        .splitBy('-----BEGIN-----\n')
        .splitBy('\n-----END-----\n')
        .filter(chunk => chunk !== '')
        .each(function (x) {

            requests.push(function (next) {
                Helpers.Authenticate()
                    .then(function (response1) {
                        return Helpers.Retrieve();
                    })
                    .then(function (response2) {
                        return Helpers.Retrieve();
                    })
                    .then(function () {
                        next();
                    });
            });

        });
        console.log(requests)
        async.series(requests);

最佳答案

刚刚阅读highland's医生。尝试将 .done 添加到您的流中,并将 console.log 添加到 requests 中。

_(fs.createReadStream("small.txt", { encoding: 'utf8' }))
    .splitBy('-----BEGIN-----\n')
    .splitBy('\n-----END-----\n')
    .filter(chunk => chunk !== '')
    .each(function (x) {

        requests.push(function (next) {
            Helpers.Authenticate()
                .then(function (response1) {
                    return Helpers.Retrieve();
                })
                .then(function (response2) {
                    return Helpers.Retrieve();
                })
                .then(function () {
                    next();
                });
        });

    }).done(function(){
      console.log(requests);
    });

关于javascript - 从大文件流式传输并创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39663142/

相关文章:

node.js - 将 postman api 调用转换为 Node.js 调用

javascript - 当用户在 laravel 5 中关闭浏览器时如何在 Controller 中运行方法

javascript - 如果我在单个 html 中有多个 ui-view,如何替换单个 ui-view

javascript - FramerJS:重新排序数组

javascript - 如何摧毁高地溪流

javascript - 从 promise 创建高地溪流时如何处理 promise 拒绝?

javascript - Backbone.js View 和模型相关性?

node.js - 如何在Windows上使用nexe编译nodejs文件?

javascript - 环回远程方法关系列表到 JSON