Skip to content

Commit 9c9ec60

Browse files
committed
fix: fix offset & limit default value setter of hash generator
1 parent a1c90f3 commit 9c9ec60

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

util/compare.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function getFileSummary (base = '', paths = [], queue = null) {
1111
_.each(paths, async path => {
1212
await queue.add(() => {
1313
const filename = UtilPath.relative(base, path)
14-
const md5 = UtilHash.getHash(path, { offset: 0, limit: 30 * 1024 * 1024 })
14+
const md5 = UtilHash.getHash(path, { offset: 0, limit: 100 * 1024 })
1515

1616
const pack = {
1717
path,

util/hash.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import _ from 'lodash'
12
import MD5 from 'md5'
23
import FsExtra from 'fs-extra'
34

45
function getHash (path = '', opts = {}) {
5-
const offset = +opts.offset || 50
6-
const limit = +opts.limit || 102400
6+
const offset = +opts.offset
7+
const offsetVal = _.isFinite(offset) ? offset : 0
8+
const limit = +opts.limit
9+
const limitVal = _.isFinite(limit) ? limit : 102400
710
const fd = FsExtra.openSync(path, 'r')
811
const fstat = FsExtra.fstatSync(fd)
9-
const bufSize = fstat.size - offset > limit ? limit : fstat.size - offset
12+
const bufSize = fstat.size - offsetVal > limitVal ? limitVal : fstat.size - offsetVal
1013
const buf = Buffer.alloc(bufSize)
11-
FsExtra.readSync(fd, buf, 0, bufSize, offset)
14+
FsExtra.readSync(fd, buf, 0, bufSize, offsetVal)
1215
FsExtra.closeSync(fd)
1316
const md5 = MD5(buf)
1417

0 commit comments

Comments
 (0)