mirror of
https://github.com/gradle/wrapper-validation-action
synced 2024-11-23 17:22:01 +00:00
Properly close file read stream
Signed-off-by: Paul Merlin <paul@gradle.com>
This commit is contained in:
parent
bdf490fd65
commit
94a3288680
5 changed files with 23 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
import * as checksums from '../src/checksums'
|
||||
|
||||
test('fetches wrapper jars checksums', async () => {
|
||||
let validChecksums = await checksums.fetchValidChecksums(false)
|
||||
const validChecksums = await checksums.fetchValidChecksums(false)
|
||||
expect(validChecksums.length).toBeGreaterThan(10)
|
||||
})
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as path from 'path'
|
|||
import * as hash from '../src/hash'
|
||||
|
||||
test('can sha256 files', async () => {
|
||||
let sha = await hash.sha256File(
|
||||
const sha = await hash.sha256File(
|
||||
path.resolve('__tests__/data/invalid/gradle-wrapper.jar')
|
||||
)
|
||||
expect(sha).toEqual(
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as path from 'path'
|
|||
import * as validate from '../src/validate'
|
||||
|
||||
test('validates wrapper jars', async () => {
|
||||
let invalidWrapperJars = await validate.findInvalidWrapperJars(
|
||||
const invalidWrapperJars = await validate.findInvalidWrapperJars(
|
||||
path.resolve('.'),
|
||||
false
|
||||
)
|
||||
|
|
14
dist/index.js
vendored
14
dist/index.js
vendored
|
@ -19546,10 +19546,16 @@ function sha256File(path) {
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hash = crypto.createHash('sha256');
|
||||
fs.createReadStream(path)
|
||||
.on('data', data => hash.update(data))
|
||||
.on('end', () => resolve(hash.digest('hex')))
|
||||
.on('error', error => reject(error));
|
||||
const stream = fs.createReadStream(path);
|
||||
stream.on('data', data => hash.update(data));
|
||||
stream.on('end', () => {
|
||||
stream.destroy();
|
||||
resolve(hash.digest('hex'));
|
||||
});
|
||||
stream.on('error', error => {
|
||||
stream.destroy();
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
14
src/hash.ts
14
src/hash.ts
|
@ -4,9 +4,15 @@ import * as fs from 'fs'
|
|||
export async function sha256File(path: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hash = crypto.createHash('sha256')
|
||||
fs.createReadStream(path)
|
||||
.on('data', data => hash.update(data))
|
||||
.on('end', () => resolve(hash.digest('hex')))
|
||||
.on('error', error => reject(error))
|
||||
const stream = fs.createReadStream(path)
|
||||
stream.on('data', data => hash.update(data))
|
||||
stream.on('end', () => {
|
||||
stream.destroy()
|
||||
resolve(hash.digest('hex'))
|
||||
})
|
||||
stream.on('error', error => {
|
||||
stream.destroy()
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue