toCSVDirectory method
Saves the DataCube to a directory of CSV files.
Each sheet (depth level) is saved as a separate CSV file. Files are named: sheet_0.csv, sheet_1.csv, etc.
Note: This method requires dart:io and is only available on non-web platforms.
Example:
var cube = DataCube.zeros(3, 4, 5);
await cube.toCSVDirectory('cube_data');
// Creates: cube_data/sheet_0.csv, cube_data/sheet_1.csv, cube_data/sheet_2.csv
Implementation
Future<void> toCSVDirectory(String dirPath) async {
final fileIO = FileIO();
// Create directory if needed (platform-specific)
await _ensureDirectoryExists(dirPath);
// Save metadata
final metadata = {
'type': 'DataCube',
'version': '1.0',
'depth': depth,
'rows': rows,
'columns': columns,
'attributes': attrs.toJson(),
};
await fileIO.saveToFile('$dirPath/metadata.json', jsonEncode(metadata));
// Save each sheet as CSV
for (int d = 0; d < depth; d++) {
final frame = getFrame(d);
await fileIO.saveToFile('$dirPath/sheet_$d.csv', _dataFrameToCSV(frame));
}
}