fGetObject method
Downloads and saves the object as a file in the local filesystem.
Implementation
Future<void> fGetObject(
String bucket,
String object,
String filePath,
) async {
MinioInvalidBucketNameError.check(bucket);
MinioInvalidObjectNameError.check(object);
final stat = await statObject(bucket, object);
final dir = dirname(filePath);
await Directory(dir).create(recursive: true);
final partFileName = '$filePath.${stat.etag}.part.minio';
final partFile = File(partFileName);
IOSink partFileStream;
var offset = 0;
Future<void> rename() async {
await partFile.rename(filePath);
}
if (partFile.existsSync()) {
final localStat = partFile.statSync();
if (stat.size == localStat.size) return rename();
offset = localStat.size;
partFileStream = partFile.openWrite(mode: FileMode.append);
} else {
partFileStream = partFile.openWrite();
}
final dataStream = await getPartialObject(bucket, object, offset);
await dataStream.pipe(partFileStream);
final localStat = partFile.statSync();
if (localStat.size != stat.size) {
throw MinioError('Size mismatch between downloaded file and the object');
}
return rename();
}