gpt4 book ai didi

node.js - 在 Node.js 中捕获 fatal error | fatal error : CALL_AND_RETRY_0 Allocation failed - process out of memory

转载 作者:搜寻专家 更新时间:2023-11-01 00:02:00 24 4
gpt4 key购买 nike

我想知道是否有办法捕获这个错误:

FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory

我试过:

process.on('uncaughtException', function(err){
//do something
})

但这并没有捕获到错误。

任何帮助将不胜感激

P.S 当为大约 18 个文件的字符串生成 MD5 哈希值时会发生这种情况,我正在像这样使用 md5 模块:

for(i=0;i<array.length;i++){
fs.readFile(array[i], function(err,buf){
console.log(mdf(buf))
})

}

最佳答案

您应该避免在内存中缓冲整个文件。相反,一次计算一个 block 的 md5 散列。示例:

var fs = require('fs'),
crypto = require('crypto');

var array = [ 'foo.txt' ];

array.forEach(function(filename) {
var hasher = crypto.createHash('md5', { encoding: 'hex' });
fs.createReadStream(filename).pipe(hasher).on('finish', function() {
process.nextTick(function() {
var md5sum = hasher.read();
console.log(filename + ': ' + md5sum);
});
});
});

关于node.js - 在 Node.js 中捕获 fatal error | fatal error : CALL_AND_RETRY_0 Allocation failed - process out of memory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25192656/

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