@pstdio/opfs-utils
Version:
Utilities for the browser's OPFS: ls, grep, safe file read, unified diff patching, and MIME helpers.
49 lines (48 loc) • 2.41 kB
TypeScript
import { ErrorType } from '../errors';
export declare const DEFAULT_MAX_LINES_TEXT_FILE = 2000;
export declare const MAX_LINE_LENGTH_TEXT_FILE = 2000;
export declare const DEFAULT_ENCODING: "utf-8";
export declare function getSpecificMimeType(filePathOrName: string): string | undefined;
export declare function registerMimeTypes(map: Record<string, string>): void;
/**
* Checks if a path is within a given root directory (both POSIX-like strings).
*/
export { isWithinRoot } from './path';
/**
* Determines if a file is likely binary based on content sampling.
* @param file A File object (from OPFS)
*/
export declare function isBinaryFile(file: File): Promise<boolean>;
/**
* Detects the type of file based on extension and content.
* @param fileName Name or path of the file (used for extension/MIME lookup).
* @param file Optional File for content-based fallback.
*/
export declare function detectFileType(fileName: string, file?: File): Promise<"text" | "image" | "pdf" | "audio" | "video" | "binary" | "svg">;
export interface ProcessedFileReadResult {
llmContent: any;
returnDisplay: string;
error?: string;
errorType?: ErrorType;
isTruncated?: boolean;
originalLineCount?: number;
linesShown?: [number, number];
}
export interface ProcessSingleFileOptions {
/** Maximum file size in megabytes for text read path (default 20). */
maxFileSizeMB?: number;
/** Default max lines when `limit` is not specified (default 2000). */
defaultMaxLines?: number;
/** Max characters per line before truncation (default 2000). */
maxLineLength?: number;
}
/**
* Reads and processes a single file in OPFS, handling text, images, and PDFs.
* @param filePath POSIX-like path within OPFS (e.g., 'project/src/index.ts').
* @param rootDirectory POSIX-like path used as the logical project root for display (e.g., 'project').
* @param _unused (ignored) legacy third parameter kept for backward compatibility.
* @param offset Optional offset for text files (0-based line number).
* @param limit Optional limit for text files (number of lines to read).
* @param options Optional thresholds to override defaults (file size, lines, line length).
*/
export declare function processSingleFileContent(filePath: string, rootDirectory: string, _unused?: unknown, offset?: number, limit?: number, options?: ProcessSingleFileOptions): Promise<ProcessedFileReadResult>;