calculateFileHash (utils/index.ts)

vibesdk · files, Files / Storage

* Calculate SHA256 hash of content (first 32 chars) This matches Cloudflare's expected hash format /

// Source: https://github.com/mperkins0155/vibesdk | License: MIT | Copyright 2025 Cloudflare
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Calculate SHA256 hash of content (first 32 chars)
 * This matches Cloudflare's expected hash format
 */
export async function calculateFileHash(content: ArrayBuffer): Promise<string> {
	const hashBuffer = await crypto.subtle.digest('SHA-256', content);
	const hashArray = Array.from(new Uint8Array(hashBuffer));
	const hashHex = hashArray
		.map((b) => b.toString(16).padStart(2, '0'))
		.join('');
	return hashHex.substring(0, 32);
}

/**
 * Determine MIME type based on file extension
 * Critical for proper asset serving in browsers
 */
export function getMimeType(filePath: string): string {
	const ext = filePath.split('.').pop()

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key