File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,18 @@ import 'dart:io';
22import 'dart:math' ;
33
44import 'package:exif/exif.dart' ;
5+ import 'package:gpth/utils.dart' ;
6+ import 'package:mime/mime.dart' ;
57
68/// DateTime from exif data *potentially* hidden within a [file]
79///
810/// You can try this with *any* file, it either works or not 🤷
911Future <DateTime ?> exifExtractor (File file) async {
12+ // if file is not image or >32MiB - DO NOT crash :D
13+ if (! (lookupMimeType (file.path)? .startsWith ('image/' ) ?? false ) ||
14+ await file.length () > maxFileSize) {
15+ return null ;
16+ }
1017 final bytes = await file.readAsBytes ();
1118 // this returns empty {} if file doesn't have exif so don't worry
1219 final tags = await readExifFromBytes (bytes);
Original file line number Diff line number Diff line change 11import 'dart:io' ;
22
33import 'package:crypto/crypto.dart' ;
4+ import 'package:gpth/utils.dart' ;
45
56/// Abstract of a *media* - a photo or video
67/// Main thing is the [file] - this should not change
@@ -34,7 +35,10 @@ class Media {
3435 Digest ? _hash;
3536
3637 /// will be used for finding duplicates/albums
37- Digest get hash => _hash ?? = sha256.convert (file.readAsBytesSync ());
38+ /// WARNING: Returns same value for files > [maxFileSize]
39+ Digest get hash => _hash ?? = file.lengthSync () > maxFileSize
40+ ? Digest ([0 ])
41+ : sha256.convert (file.readAsBytesSync ());
3842
3943 Media (
4044 this .file, {
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ import 'package:proper_filesize/proper_filesize.dart';
99// remember to bump this
1010const version = '3.3.2' ;
1111
12+ /// max file size to read for exif/hash/anything
13+ const maxFileSize = 64 * 1024 * 1024 ;
14+
1215/// convenient print for errors
1316void error (Object ? object) => stderr.write ('$object \n ' );
1417
You can’t perform that action at this time.
0 commit comments