fromStream static method
Implementation
static Future<RamFileData> fromStream(
Stream<List<int>> source,
int fileLength, {
@Deprecated('Visible for testing only') int? subListMaxSize,
}) async {
final List<List<int>> list = <List<int>>[];
int? usedSubListSize;
bool listSizeChanged = false;
await for (final List<int> intList in source) {
if (usedSubListSize == null) {
usedSubListSize = intList.length;
} else if (listSizeChanged) {
throw Exception(
'RamFileData.fromStream: an non-ending entry of the stream has a different size from its predecessors.',
);
} else if (intList.length != usedSubListSize) {
if (intList.length > usedSubListSize) {
throw Exception(
'RamFileData.fromStream: an entry of the stream had a larger size than its predecessors',
);
}
listSizeChanged = true;
}
list.add(intList);
}
if (usedSubListSize == null) {
throw Exception('RamFileData.fromStream: usedSubListSize is null');
}
return RamFileData._(list, usedSubListSize, fileLength, true);
}