import { fs, path } from "@llamaindex/env";
/**
 * A FileReader takes file paths and imports data into Document objects.
 */ export class FileReader {
    async loadData(filePath) {
        const fileContent = await fs.readFile(filePath);
        const docs = await this.loadDataAsContent(fileContent);
        docs.forEach(FileReader.addMetaData(filePath));
        return docs;
    }
    static addMetaData(filePath) {
        return (doc, index)=>{
            // generate id as loadDataAsContent is only responsible for the content
            doc.id_ = `${filePath}_${index + 1}`;
            doc.metadata["file_path"] = path.resolve(filePath);
            doc.metadata["file_name"] = path.basename(filePath);
        };
    }
}
