mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 01:28:26 -05:00
Merge from vscode cfc1ab4c5f816765b91fb7ead3c3427a7c8581a3
This commit is contained in:
@@ -5,19 +5,17 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as crypto from 'crypto';
|
||||
import * as stream from 'stream';
|
||||
import { once } from 'vs/base/common/functional';
|
||||
|
||||
export function checksum(path: string, sha1hash: string | undefined): Promise<void> {
|
||||
const promise = new Promise<string | undefined>((c, e) => {
|
||||
const input = fs.createReadStream(path);
|
||||
const hash = crypto.createHash('sha1');
|
||||
const hashStream = hash as any as stream.PassThrough;
|
||||
input.pipe(hashStream);
|
||||
input.pipe(hash);
|
||||
|
||||
const done = once((err?: Error, result?: string) => {
|
||||
input.removeAllListeners();
|
||||
hashStream.removeAllListeners();
|
||||
hash.removeAllListeners();
|
||||
|
||||
if (err) {
|
||||
e(err);
|
||||
@@ -28,8 +26,8 @@ export function checksum(path: string, sha1hash: string | undefined): Promise<vo
|
||||
|
||||
input.once('error', done);
|
||||
input.once('end', done);
|
||||
hashStream.once('error', done);
|
||||
hashStream.once('data', (data: Buffer) => done(undefined, data.toString('hex')));
|
||||
hash.once('error', done);
|
||||
hash.once('data', (data: Buffer) => done(undefined, data.toString('hex')));
|
||||
});
|
||||
|
||||
return promise.then(hash => {
|
||||
|
||||
Reference in New Issue
Block a user