读取和写入流时打开的文件太多

时间:2016-06-02 22:00:33

标签: node.js fs

我想弄清楚我有以下错误:

Error: EMFILE: too many open files, open '...\logs\...'

我实际上正在读取文件,并从这些文件中写入输出,循环通过返回promise的函数。

var input = fs.createReadStream(dirpath).pipe(es.split())
        .pipe(es.mapSync(function(line){
          ...
          output = fs.createWriteStream(folderOutput + id + '.xml');

          output.write(documentNode, function(err) {
                input.end();
                output.end();
          });

          output.on('close', function (err) {
            outputClosed=true;
            console.log('output has been destroyed and file has been closed');
            if (outputClosed && inputClosed)
                resolve();
          });

          input.on('close', function (err) {
            inputClosed=true;
            console.log('input has been destroyed and file has been closed');
            if (outputClosed && inputClosed)
                resolve();
            });
          });
        })
  );

过了一会儿(处理了很多文件),我有太多的打开文件错误。知道我在那里做错了什么?

0 个答案:

没有答案