listObjectsQuery method

Future<ListObjectsOutput> listObjectsQuery(
  1. String bucket,
  2. String prefix,
  3. String? marker,
  4. String delimiter,
  5. int? maxKeys,
)

list a batch of objects

Implementation

Future<ListObjectsOutput> listObjectsQuery(
  String bucket,
  String prefix,
  String? marker,
  String delimiter,
  int? maxKeys,
) async {
  MinioInvalidBucketNameError.check(bucket);
  MinioInvalidPrefixError.check(prefix);

  final queries = <String, dynamic>{};
  queries['prefix'] = prefix;
  queries['delimiter'] = delimiter;

  if (marker != null) {
    queries['marker'] = marker;
  }

  if (maxKeys != null) {
    maxKeys = maxKeys >= 1000 ? 1000 : maxKeys;
    queries['maxKeys'] = maxKeys.toString();
  }

  final resp = await _client.request(
    method: 'GET',
    bucket: bucket,
    queries: queries,
  );

  validate(resp);

  final node = xml.XmlDocument.parse(resp.body);
  final isTruncated = getNodeProp(node.rootElement, 'IsTruncated')!.text;
  final nextMarker = getNodeProp(node.rootElement, 'NextMarker')?.text;
  final objs = node.findAllElements('Contents').map((c) => Object.fromXml(c));
  final prefixes = node
      .findAllElements('CommonPrefixes')
      .map((c) => CommonPrefix.fromXml(c));

  return ListObjectsOutput()
    ..contents = objs.toList()
    ..commonPrefixes = prefixes.toList()
    ..isTruncated = isTruncated.toLowerCase() == 'true'
    ..nextMarker = nextMarker;
}