@@ -7,8 +7,8 @@ import * as fs from 'fs';
77import * as crypto from 'crypto' ;
88import { once } from 'vs/base/common/functional' ;
99
10- export function checksum ( path : string , sha1hash : string | undefined ) : Promise < void > {
11- const promise = new Promise < string | undefined > ( ( c , e ) => {
10+ export async function checksum ( path : string , sha1hash : string | undefined ) : Promise < void > {
11+ const checksumPromise = new Promise < string | undefined > ( ( resolve , reject ) => {
1212 const input = fs . createReadStream ( path ) ;
1313 const hash = crypto . createHash ( 'sha1' ) ;
1414 input . pipe ( hash ) ;
@@ -18,9 +18,9 @@ export function checksum(path: string, sha1hash: string | undefined): Promise<vo
1818 hash . removeAllListeners ( ) ;
1919
2020 if ( err ) {
21- e ( err ) ;
21+ reject ( err ) ;
2222 } else {
23- c ( result ) ;
23+ resolve ( result ) ;
2424 }
2525 } ) ;
2626
@@ -30,11 +30,9 @@ export function checksum(path: string, sha1hash: string | undefined): Promise<vo
3030 hash . once ( 'data' , ( data : Buffer ) => done ( undefined , data . toString ( 'hex' ) ) ) ;
3131 } ) ;
3232
33- return promise . then ( hash => {
34- if ( hash !== sha1hash ) {
35- return Promise . reject ( new Error ( 'Hash mismatch' ) ) ;
36- }
33+ const hash = await checksumPromise ;
3734
38- return Promise . resolve ( ) ;
39- } ) ;
35+ if ( hash !== sha1hash ) {
36+ throw new Error ( 'Hash mismatch' ) ;
37+ }
4038}
0 commit comments