FileReader class

Generic file reader that automatically detects and handles multiple file formats.

FileReader provides a unified interface for reading various file formats into DataFrames. It automatically detects the file format based on the file extension and uses the appropriate reader implementation.

Supported Formats

  • CSV (.csv): Comma-separated values using CsvReader
  • Excel (.xlsx, .xls): Excel workbooks using ExcelFileReader
  • JSON (.json): JSON files with multiple orientations using JsonReader
  • HDF5 (.h5, .hdf5): HDF5 scientific data format using HDF5Reader
  • MATLAB (.mat): MATLAB v7.3 MAT-files using MATReader
  • Parquet (.parquet, .pq): Parquet columnar format (basic implementation)

Features

  • Automatic format detection by file extension
  • Format-specific options support
  • Convenient wrapper methods for each format
  • Multi-sheet Excel support
  • HDF5 dataset inspection

Example

// Auto-detect format
final df = await FileReader.read('data.csv');

// Format-specific methods
final csvDf = await FileReader.readCsv('data.csv',
  fieldDelimiter: ';',
  hasHeader: true,
);

final excelDf = await FileReader.readExcel('data.xlsx',
  sheetName: 'Sheet1',
  skipRows: 1,
);

// Read all Excel sheets
final sheets = await FileReader.readAllExcelSheets('workbook.xlsx');

// JSON operations
final jsonDf = await FileReader.readJson('data.json',
  orient: 'records',
);

// HDF5 operations
final hdf5Df = await FileReader.readHDF5('data.h5',
  dataset: '/mydata',
);
final info = await FileReader.inspectHDF5('data.h5');

See also:

Constructors

FileReader()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

inspectHDF5(String path) Future<Map<String, dynamic>>
Inspects an HDF5 file structure and returns metadata.
inspectMAT(String path) Future<Map<String, dynamic>>
Inspects a MATLAB .mat file structure and returns metadata.
listExcelSheets(String path) Future<List<String>>
Lists all sheet names in an Excel file without reading the data.
listHDF5Datasets(String path) Future<List<String>>
Lists all datasets in an HDF5 file.
listMATVariables(String path) Future<List<String>>
Lists all MATLAB variables in a .mat file.
read(String path, {Map<String, dynamic>? options}) Future<DataFrame>
Reads a file and returns a DataFrame, automatically detecting format by extension.
readAllExcelSheets(String path, {bool hasHeader = true, int? skipRows, int? maxRows, List<String>? columnNames, Map<String, dynamic>? options}) Future<Map<String, DataFrame>>
Reads all sheets from an Excel file and returns a Map of sheet names to DataFrames
readCsv(String path, {String fieldDelimiter = ',', String textDelimiter = '"', String? textEndDelimiter, String? eol, bool hasHeader = true, int? skipRows, int? maxRows, List<String>? columnNames, Map<String, dynamic>? options}) Future<DataFrame>
Reads a CSV (Comma-Separated Values) file into a DataFrame.
readExcel(String path, {String? sheetName, bool hasHeader = true, int? skipRows, int? maxRows, List<String>? columnNames, Map<String, dynamic>? options}) Future<DataFrame>
Reads an Excel file (.xlsx, .xls) into a DataFrame.
readHDF5(String path, {String? dataset, Map<String, dynamic>? options}) Future<DataFrame>
Reads an HDF5 file into a DataFrame.
readJson(String path, {String orient = 'records', List<String>? columns, Map<String, dynamic>? options}) Future<DataFrame>
Reads a JSON file into a DataFrame.
readMAT(String path, {String? variable, Map<String, dynamic>? options}) Future<DataFrame>
Reads a MATLAB .mat file variable into a DataFrame.
readParquet(String path, {Map<String, dynamic>? options}) Future<DataFrame>
Reads a Parquet file into a DataFrame.