Repository Public
1"use client";2/** Hands a generated text file to the browser's download flow. Nothing is uploaded anywhere. */3export function downloadText(filename: string, text: string, mime = "text/plain"): void {4 const url = URL.createObjectURL(new Blob([text], { type: `${mime};charset=utf-8` }));5 const a = document.createElement("a");6 a.href = url; a.download = filename;7 document.body.appendChild(a); a.click(); a.remove();8 setTimeout(() => URL.revokeObjectURL(url), 1000);9}1011/** Reads a file chosen by the visitor, refusing anything larger than `maxBytes`. */12export async function readTextFile(file: File, maxBytes = 5_000_000): Promise<string | null> {13 if (file.size > maxBytes) return null;14 return file.text();15}16