Skip to content

Commit

Permalink
refactor(box): reduce Stream (#4333)
Browse files Browse the repository at this point in the history
  • Loading branch information
segayuu committed May 30, 2020
1 parent aa05810 commit e8953e6
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/box/index.js
Expand Up @@ -216,20 +216,17 @@ function escapeBackslash(path) {
}

function getHash(path) {
return new Promise((resolve, reject) => {
const src = createReadStream(path);
const hasher = createSha1Hash();
let hash_value;

src.pipe(hasher)
.on('data', chunk => {
hash_value = chunk.toString('hex');
})
.on('end', () => {
resolve(hash_value);
})
.on('error', reject);
const src = createReadStream(path);
const hasher = createSha1Hash();

const finishedPromise = new Promise((resolve, reject) => {
src.once('error', reject);
src.once('end', resolve);
});

src.on('data', chunk => { hasher.update(chunk); });

return finishedPromise.then(() => hasher.digest('hex'));
}

function toRegExp(ctx, arg) {
Expand Down

0 comments on commit e8953e6

Please sign in to comment.