mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
38 lines
829 B
Dart
38 lines
829 B
Dart
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:image_size_getter/image_size_getter.dart';
|
|
|
|
class AsyncMemoryInput extends AsyncImageInput {
|
|
final Uint8List bytes;
|
|
const AsyncMemoryInput(this.bytes);
|
|
|
|
factory AsyncMemoryInput.byteBuffer(ByteBuffer buffer) =>
|
|
AsyncMemoryInput(buffer.asUint8List());
|
|
|
|
@override
|
|
getRange(int start, int end) async => bytes.sublist(start, end);
|
|
|
|
@override
|
|
get length async => bytes.length;
|
|
|
|
@override
|
|
exists() async => bytes.isNotEmpty;
|
|
}
|
|
|
|
class AsyncFileInput extends AsyncImageInput {
|
|
final File file;
|
|
|
|
AsyncFileInput(this.file);
|
|
|
|
@override
|
|
getRange(int start, int end) => file
|
|
.openRead(start, end)
|
|
.reduce((previous, element) => previous + element);
|
|
|
|
@override
|
|
get length => file.length();
|
|
|
|
@override
|
|
exists() => file.exists();
|
|
}
|