toJson method

Map<String, dynamic> toJson()

Converts this stat to a Kubo-compatible JSON map.

Kubo's files stat always returns the full object over HTTP (the --hash/--size flags only affect the CLI text format), and Mode is serialized as a four-digit octal string, omitted when unset.

Implementation

Map<String, dynamic> toJson() {
  final result = <String, dynamic>{
    'Hash': hash,
    'Size': size,
    'CumulativeSize': cumulativeSize,
    'Blocks': blocks,
    'Type': type,
  };
  if (withLocal == true) {
    result['WithLocality'] = true;
    result['Local'] = local ?? true;
    result['SizeLocal'] = sizeLocal ?? cumulativeSize;
  }
  final m = mode;
  if (m != null && m != 0) {
    result['Mode'] = m.toRadixString(8).padLeft(4, '0');
  }
  if (mtime != null) result['Mtime'] = mtime;
  if (mtimeNsecs != null) result['MtimeNsecs'] = mtimeNsecs;
  return result;
}