Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xsline OpenChatCut Sha256File

From Leeroopedia
Knowledge Sources
Domains Hashing, Deduplication, Media_Import
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete function that computes a SHA-256 hash of a file by streaming its contents, returning a lowercase 64-character hex digest.

Description

The sha256File function uses Node.js `crypto.createHash('sha256')` with a streaming file read to avoid loading the entire file into memory. It is the hashing primitive used by importLocalMedia during the content-hash deduplication stage.

Key properties:

  • Streaming: Reads the file in chunks through `node:fs/promises` to handle large files without memory pressure.
  • Deterministic: Same file content always produces the same hash.
  • Canonical form: Returns a lowercase hex digest.

Usage

  • Media import: Called by `importLocalMedia` for files under 1.5 GB.
  • Deduplication: The hash is compared against existing media to detect duplicates.

Code Reference

Source Location

  • Repository: OpenChatCut
  • File:*** shared/node-content-hash.ts

Signature

export async function sha256File(path: string): Promise<string>;

Import

import { sha256File } from '../shared/node-content-hash.ts';

I/O Contract

Inputs

Name Type Required Description
path string Yes Absolute path to the file to hash

Outputs

Name Type Description
sha256File() returns string Lowercase 64-char SHA-256 hex digest

Usage Examples

Hash a File

import { sha256File } from '../shared/node-content-hash.ts';

const hash = await sha256File('/media/uploads/source.mp4');
console.log(`SHA-256: ${hash}`);
// Example: "a1b2c3d4e5f6...64 chars total"

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment