mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Covered the following paths: * Files put directly into `lib/plugins/aws/package/compile` * Files put directly into `lib/plugins/aws/package` * `lib/plugins/aws/package/lib` Made changes to tests where necessary.
34 lines
848 B
JavaScript
34 lines
848 B
JavaScript
'use strict';
|
|
|
|
const memoize = require('memoizee');
|
|
const crypto = require('crypto');
|
|
const fs = require('fs');
|
|
|
|
const getHashForFilePath = memoize(
|
|
async (filePath) => {
|
|
const fileHash = crypto.createHash('sha256');
|
|
fileHash.setEncoding('base64');
|
|
return new Promise((resolve, reject) => {
|
|
const readStream = fs.createReadStream(filePath);
|
|
readStream
|
|
.on('data', (chunk) => {
|
|
fileHash.write(chunk);
|
|
})
|
|
.on('close', () => {
|
|
fileHash.end();
|
|
resolve(fileHash.read());
|
|
})
|
|
.on('error', (error) => {
|
|
reject(
|
|
new Error(
|
|
`Error: ${error} encountered during hash calculation for provided filePath: ${filePath}`
|
|
)
|
|
);
|
|
});
|
|
});
|
|
},
|
|
{ promise: true }
|
|
);
|
|
|
|
module.exports = getHashForFilePath;
|