Skip to content

Commit

Permalink
Modify generateSHA1() function to be async
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-rr committed Mar 1, 2024
1 parent 49a2be1 commit a21c8d6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Parser } from '@asyncapi/parser';
import { Specification } from 'models/SpecificationFile';
import { join, resolve } from 'path';
import { existsSync } from 'fs-extra';
import { promises as fPromises, readFileSync } from 'fs';
import { promises as fPromises } from 'fs';
import { v4 as uuidv4 } from 'uuid';
import crypto from 'crypto';

Expand Down Expand Up @@ -82,12 +82,12 @@ export default abstract class extends Command {
async finally(error: Error | undefined): Promise<any> {
await super.finally(error);
this.metricsMetadata['success'] = error === undefined;
this.metricsMetadata['source'] = this.generateSHA1();
this.metricsMetadata['source'] = await this.generateSHA1(this.specFile?.getSource() || '');
await this.recordActionFinished(this.id as string, this.metricsMetadata, this.specFile?.text());
}

generateSHA1(): any {
const fileBuffer = readFileSync(this.specFile?.getSource() || '');
async generateSHA1(filePath: string): Promise<any> {
const fileBuffer = await readFile(filePath);
const hashSum = crypto.createHash('sha1');
hashSum.update(fileBuffer);
return hashSum.digest('hex');
Expand Down

0 comments on commit a21c8d6

Please sign in to comment.