RawPFile.ofSingleStream constructor
Implementation
factory RawPFile.ofSingleStream(String name, Stream<List<int>> data,
{int? size}) {
/// The read stream getter will read the stream the first time,
/// copy it into memory and serve it from there the next time.
Stream<List<int>> getReadStream(PFile file) async* {
final pfile = file as RawPFile;
pfile._read.start();
if (pfile._isRead == false) {
log.warning("Full read of $name. SLOW!!");
var start = DateTime.now();
var buffer = BytesBuffer();
await for (var b in data) {
buffer.add(b);
yield b;
}
log.warning(
"Full read of $name in ${DateTime.now().difference(start)}");
pfile.markRead(buffer.toBytes());
return;
} else {
yield* pfile._bytes!.chunkedStream(PFile.defaultChunkSize);
}
}
return RawPFile.ofStream(name, getReadStream, size);
}