2023-05-16 09:59:31 -04:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
|
|
|
2023-09-29 03:51:46 -04:00
|
|
|
class ResoniteDBAsset {
|
2023-05-16 09:59:31 -04:00
|
|
|
final String hash;
|
|
|
|
final int bytes;
|
|
|
|
|
2023-09-29 03:51:46 -04:00
|
|
|
const ResoniteDBAsset({required this.hash, required this.bytes});
|
2023-05-16 09:59:31 -04:00
|
|
|
|
2023-09-29 03:51:46 -04:00
|
|
|
factory ResoniteDBAsset.fromMap(Map map) {
|
|
|
|
return ResoniteDBAsset(hash: map["hash"] ?? "", bytes: map["bytes"] ?? -1);
|
2023-05-16 09:59:31 -04:00
|
|
|
}
|
|
|
|
|
2023-09-29 03:51:46 -04:00
|
|
|
factory ResoniteDBAsset.fromData(Uint8List data) {
|
2023-05-16 09:59:31 -04:00
|
|
|
final digest = sha256.convert(data);
|
2023-09-29 03:51:46 -04:00
|
|
|
return ResoniteDBAsset(hash: digest.toString().replaceAll("-", "").toLowerCase(), bytes: data.length);
|
2023-05-16 09:59:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Map toMap() {
|
|
|
|
return {
|
|
|
|
"hash": hash,
|
|
|
|
"bytes": bytes,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|