prepareInput static method
Prepares a MergeInput for processing.
If the input is a path, it returns the path as is. If the input is bytes, it creates a temporary file from the bytes and returns the path to the temporary file.
Parameters:
input: The MergeInput to prepare
Returns: The path to the prepared input file
Implementation
static Future<String> prepareInput(MergeInput input) async {
switch (input.type) {
case MergeInputType.path:
return input.path!;
case MergeInputType.bytes:
final tempDirPath = getTemporalFolderPath();
final tempDir = Directory(tempDirPath);
if (!await tempDir.exists()) {
await tempDir.create(recursive: true);
}
final fileName =
'${input.type.filenamePrefix()}_${DateTime.now().millisecondsSinceEpoch}_${Random().nextInt(10000)}${input.type.extension()}';
final tempPath = p.join(tempDirPath, fileName);
final file = File(tempPath);
await file.writeAsBytes(input.bytes!);
return tempPath;
}
}