Skip to content

Commit f1a470f

Browse files
committed
crypto.checksum
1 parent b0c79f4 commit f1a470f

6 files changed

Lines changed: 52 additions & 11 deletions

File tree

src/vs/base/common/async.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,10 @@ export function sequence<T>(promiseFactory: ITask<TPromise<T>>[]): TPromise<T[]>
389389
return TPromise.as(null).then(thenHandler);
390390
}
391391

392-
export interface IFunction<A, R> {
393-
(...args: A[]): R;
394-
}
395-
396-
export function once<A, R>(fn: IFunction<A, R>): IFunction<A, R> {
392+
export function once<T extends Function>(fn: T): T {
397393
const _this = this;
398394
let didCall = false;
399-
let result: R;
395+
let result: any;
400396

401397
return function() {
402398
if (didCall) {
@@ -407,7 +403,7 @@ export function once<A, R>(fn: IFunction<A, R>): IFunction<A, R> {
407403
result = fn.apply(_this, arguments);
408404

409405
return result;
410-
};
406+
} as any as T;
411407
}
412408

413409
interface ILimitedTaskFactory {

src/vs/base/node/crypto.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import * as fs from 'fs';
9+
import * as crypto from 'crypto';
10+
import * as stream from 'stream';
11+
import { TPromise } from 'vs/base/common/winjs.base';
12+
import { once } from 'vs/base/common/async';
13+
14+
export function checksum(path: string, sha1hash: string): TPromise<void> {
15+
const promise = new TPromise<string>((c, e) => {
16+
const input = fs.createReadStream(path);
17+
const hash = crypto.createHash('sha1');
18+
const hashStream = hash as any as stream.PassThrough;
19+
input.pipe(hashStream);
20+
21+
const done = once((err?: Error, result?: string) => {
22+
input.removeAllListeners();
23+
hashStream.removeAllListeners();
24+
25+
if (err) {
26+
e(err);
27+
} else {
28+
c(result);
29+
}
30+
});
31+
32+
input.once('error', done);
33+
input.once('end', done);
34+
hashStream.once('error', done);
35+
hashStream.once('data', data => done(null, data.toString('hex')));
36+
});
37+
38+
return promise.then(hash => {
39+
if (hash !== sha1hash) {
40+
return TPromise.wrapError<void>(new Error('Hash mismatch'));
41+
}
42+
43+
return TPromise.as(null);
44+
});
45+
}

src/vs/workbench/parts/debug/browser/breakpointWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class BreakpointWidget extends ZoneWidget {
7575
setTimeout(() => this.inputBox.focus(), 0);
7676

7777
let disposed = false;
78-
const wrapUp = async.once<any, void>((success: boolean) => {
78+
const wrapUp = async.once((success: boolean) => {
7979
if (!disposed) {
8080
disposed = true;
8181
if (success) {

src/vs/workbench/parts/debug/browser/debugViewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function renderRenameBox(debugService: debug.IDebugService, contextViewService:
9999
let disposed = false;
100100
const toDispose: [lifecycle.IDisposable] = [inputBox];
101101

102-
const wrapUp = async.once<any, void>((renamed: boolean) => {
102+
const wrapUp = async.once((renamed: boolean) => {
103103
if (!disposed) {
104104
disposed = true;
105105
if (element instanceof model.Expression && renamed && inputBox.value) {

src/vs/workbench/parts/files/browser/views/explorerViewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export class FileRenderer extends ActionsRenderer implements IRenderer {
300300
inputBox.select({ start: 0, end: lastDot > 0 && !stat.isDirectory ? lastDot : value.length });
301301
inputBox.focus();
302302

303-
let done = async.once<boolean, void>(commit => {
303+
let done = async.once(commit => {
304304
tree.clearHighlight();
305305

306306
if (commit && inputBox.value) {

src/vs/workbench/parts/git/browser/gitServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ export class GitService extends ee.EventEmitter
480480
return;
481481
}
482482

483-
var onError = async.once<any, void>(e => {
483+
var onError = async.once(e => {
484484
if (!errors.isPromiseCanceledError(e)) {
485485
this.messageService.show(severity.Error, e);
486486
}

0 commit comments

Comments
 (0)