• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8421654220

25 Mar 2024 02:22PM CUT coverage: 79.934% (+53.8%) from 26.087%
8421654220

Pull #495

github

web-flow
Merge 4faeebea5 into 1869c986d
Pull Request #495: chore: add licenses for non-NPM packages

3256 of 3853 branches covered (84.51%)

25152 of 31466 relevant lines covered (79.93%)

1188.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.78
/apps/nestjs-backend/src/utils/file-utils.ts
1
import crypto from 'crypto';
2✔
2
import { createReadStream } from 'node:fs';
2✔
3
import { pipeline, Readable as ReadableStream } from 'node:stream';
2✔
4
import { promisify } from 'node:util';
2✔
5

2✔
6
const pipelineAsync = promisify(pipeline);
2✔
7

2✔
8
export class FileUtils {
2✔
9
  static async getHash(path: string): Promise<string>;
2✔
10
  static async getHash(stream: ReadableStream): Promise<string>;
2✔
11
  static async getHash(buffer: Buffer): Promise<string>;
2✔
12
  /**
2✔
13
   * Implements the overloaded method. Uses argument type checking to determine the logic to execute.
2✔
14
   * @param input A file path, ReadStream, or Buffer.
2✔
15
   * @returns A promise that resolves with the hex-encoded hash.
2✔
16
   */
2✔
17
  static async getHash(input: string | ReadableStream | Buffer): Promise<string> {
2✔
18
    let stream: ReadableStream;
13✔
19

13✔
20
    if (typeof input === 'string') {
13✔
21
      // If input is a file path, create a read stream.
13✔
22
      stream = createReadStream(input);
13✔
23
    } else if (Buffer.isBuffer(input)) {
13!
24
      // If input is a Buffer, convert it to a stream.
×
25
      stream = ReadableStream.from(input);
×
26
    } else {
×
27
      // If input is already a stream, use it as is.
×
28
      stream = input;
×
29
    }
×
30

13✔
31
    const hash = crypto.createHash('sha256');
13✔
32

13✔
33
    await pipelineAsync(stream, hash);
13✔
34

13✔
35
    return hash.digest('hex');
13✔
36
  }
13✔
37
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc