I am trying to hash a file more than 1GB using SHA256 in an Ionic 4 app based on Angular 7. I want to use this NPM module. But there is no documentation. How and where to import this module? or suggest a better alternative.
Following error I am getting: enter image description here
I have tried: import * as sha256File from 'sha256-file';
This is index.js file: there is no 'crypto' or 'fs' in the folder.
'use strict';
var crypto = require('crypto');
var fs = require('fs');
module.exports = function (filename, callback) {
var sum = crypto.createHash('sha256');
if (callback && typeof callback === 'function') {
var fileStream = fs.createReadStream(filename);
fileStream.on('error', function (err) {
return callback(err, null)
});
fileStream.on('data', function (chunk) {
try {
sum.update(chunk)
} catch (ex) {
return callback(ex, null)
}
});
fileStream.on('end', function () {
return callback(null, sum.digest('hex'))
})
} else {
sum.update(fs.readFileSync(filename));
return sum.digest('hex')
}
};