CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-stablelib--sha256

SHA-256 cryptographic hash function implementation for TypeScript and JavaScript

91

0.98x
Overview
Eval results
Files

task.mdevals/scenario-7/

File Integrity Checker

A command-line utility that computes SHA-256 checksums for files of any size using streaming to handle large files efficiently.

Capabilities

Process files in chunks

The utility must read and process files incrementally in chunks rather than loading entire files into memory at once. This ensures that even very large files (multiple gigabytes) can be processed with minimal memory usage.

  • Given a 1KB file, compute its SHA-256 hash by reading it in 1KB chunks @test
  • Given a 100MB file, compute its SHA-256 hash by reading it in 64KB chunks @test
  • The computed hash must match the expected SHA-256 hash for the file contents @test

Handle multiple files sequentially

The utility must be able to compute checksums for multiple files in a single run, processing each file independently.

  • Given three files, compute SHA-256 hashes for all three files sequentially @test

Implementation

@generates

API

/**
 * Computes the SHA-256 hash of a file by reading it in chunks.
 *
 * @param filePath - Path to the file to hash
 * @param chunkSize - Size of chunks to read (in bytes), defaults to 64KB
 * @returns Promise that resolves to the hex-encoded hash string
 */
export async function hashFile(filePath: string, chunkSize?: number): Promise<string>;

/**
 * Computes SHA-256 hashes for multiple files.
 *
 * @param filePaths - Array of file paths to hash
 * @param chunkSize - Size of chunks to read (in bytes), defaults to 64KB
 * @returns Promise that resolves to a map of file paths to their hex-encoded hashes
 */
export async function hashFiles(filePaths: string[], chunkSize?: number): Promise<Map<string, string>>;

Dependencies { .dependencies }

@stablelib/sha256 { .dependency }

Provides SHA-256 cryptographic hash functionality with support for incremental hashing.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-stablelib--sha256

tile.json