Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
if(typeof file === 'string')
return reject('Path not supported. First argument must be a File');
// @ts-ignore
const algorithm: Hash.Algorithm = (options && options.algorithm) || Hash.Algorithm[defaults.hash.algorithm as any] as Hash.Algorithm;
// @ts-ignore
const encoding = (options && options.encoding) || Hash.Encoding[defaults.hash.encoding as any] as Hash.Encoding;
if(algorithm !== Hash.Algorithm.SHA256)
return reject(new Error('Unsupported algorithm'));
const stream = new HashStream();
stream.on('error', reject);
stream.on('finish', () => resolve(stream.read().toString(encoding)));
WebFileStream.create_read_stream(file).pipe(stream);
});
}