wreckage
Version:
A convenient, modern request library built around Wreck. A fork of Wrecked.
31 lines (22 loc) • 567 B
JavaScript
import crypto from 'crypto';
import wreck from 'wreck';
const read = async (response, options = {}) => {
let hash;
if (options.hash) {
const hashType = typeof options.hash === 'string' ? options.hash : 'sha1';
const hashData = crypto.createHash(hashType);
response.on('data', chunk => {
hashData.update(chunk);
});
response.on('end', () => {
hash = hashData.digest('hex');
});
}
const data = await wreck.read(response, options);
const payload = {
data,
hash
};
return payload;
};
export default read;