decodeRmlExportedFiles function

List<RmlExportedFile> decodeRmlExportedFiles(
  1. Uint8List bundle
)

Decodes the bundle an export returns. Throws a FormatException when the bundle is cut short or runs past its last file.

Implementation

List<RmlExportedFile> decodeRmlExportedFiles(Uint8List bundle) {
  if (bundle.isEmpty) {
    return const [];
  }
  final cursor = [0];
  final count = _readVarUint(bundle, cursor);
  final files = <RmlExportedFile>[];
  for (var i = 0; i < count; i++) {
    final path = utf8.decode(_readBytes(bundle, cursor), allowMalformed: true);
    final flags = _readVarUint(bundle, cursor);
    final bytes = _readBytes(bundle, cursor);
    files.add(
      RmlExportedFile(
        path: path,
        bytes: Uint8List.fromList(bytes),
        bytesOmitted: flags & _flagBytesOmitted != 0,
      ),
    );
  }
  if (cursor[0] != bundle.length) {
    throw const FormatException('file bundle has bytes past its last file');
  }
  return files;
}