channel_io.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import 'dart:typed_data';
  2. import 'package:fis_vid/async_vid/cached/vid_data.dart';
  3. import 'package:fis_vid/async_vid/http/vid_data.dart';
  4. import 'package:fis_vid/async_vid/vid_data.dart';
  5. import 'package:fis_vid/cache/io.dart';
  6. import 'package:vid/us/vid_us_data_http_reader.dart';
  7. import 'channel.dart';
  8. class VidDataChannelImpl extends VidDataChannel {
  9. VidDataChannelImpl(String url) : super(url);
  10. static void receiveChunk(String id, Uint8List chunk) {}
  11. @override
  12. Future<AsyncVidImageDataBase> buildSource() async {
  13. final cacheBuffer = await VidNativeCache.ins.getCache(url);
  14. if (cacheBuffer != null) {
  15. return AsyncCachedVidImageData(
  16. cacheBuffer,
  17. downloadCallback: onDownloadCallback,
  18. );
  19. }
  20. return AsyncHttpVidImageData(
  21. url,
  22. downloadCallback: _onHttpDownloadCallback,
  23. );
  24. }
  25. void _onHttpDownloadCallback(double progress, DownloadErrorException? error) {
  26. if (progress >= 1) {
  27. final bytes = source!.getDownloadedData();
  28. VidNativeCache.ins.saveCache(url, bytes);
  29. }
  30. onDownloadCallback(progress, error);
  31. }
  32. }