Skip to content

Commit

Permalink
Remove changes from cache and mime
Browse files Browse the repository at this point in the history
  • Loading branch information
Alienjob committed Dec 28, 2023
1 parent e0437aa commit 8a4d16f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
40 changes: 0 additions & 40 deletions lib/ui/worker/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_thumbhash/flutter_thumbhash.dart' as t;
import 'package:get/get.dart' hide Response;
import 'package:hive/hive.dart';
import 'package:http_parser/http_parser.dart';
import 'package:mutex/mutex.dart';
import 'package:open_file/open_file.dart';
import 'package:path/path.dart' as p;
Expand All @@ -38,7 +37,6 @@ import '/domain/service/disposable_service.dart';
import '/provider/hive/cache.dart';
import '/provider/hive/download.dart';
import '/util/backoff.dart';
import '/util/mime.dart';
import '/util/obs/rxmap.dart';
import '/util/platform_utils.dart';

Expand Down Expand Up @@ -662,44 +660,6 @@ class CacheEntry {

/// Byte data of this [CacheEntry].
final Uint8List? bytes;

/// [MediaType] of this [CacheEntry].
Future<MediaType?> get type async {
if (!_typeResolved) {
_type = await _resolveType();
}

return _type;
}

/// [MediaType] type of this [CacheEntry].
MediaType? _type;

/// Indicator whether [_type] is determined, used to prevent double
/// [_resolveType] invoking.
bool _typeResolved = false;

/// Resolves the [MediaType] of [bytes]/[file] of this [CacheEntry].
Future<MediaType?> _resolveType() async {
String? mime;

if (bytes != null) {
List<int>? headerBytes =
bytes?.take(MimeResolver.resolver.magicNumbersMaxLength).toList();
mime = MimeResolver.lookup('', headerBytes: headerBytes);
} else if (file != null) {
List<int>? headerBytes = [];
await for (var part
in file!.openRead(0, MimeResolver.resolver.magicNumbersMaxLength)) {
headerBytes.addAll(part);
}
mime = MimeResolver.lookup('', headerBytes: headerBytes);
}

_typeResolved = true;

return mime == null ? null : MediaType.parse(mime);
}
}

/// Response type of the [CacheWorker.get] function.
Expand Down
15 changes: 0 additions & 15 deletions lib/util/mime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with this program. If not, see
// <https://www.gnu.org/licenses/agpl-3.0.html>.

import 'package:http_parser/http_parser.dart';
import 'package:mime/mime.dart';

/// Wrapper around [MimeTypeResolver] resolving MIME-types.
Expand Down Expand Up @@ -48,17 +47,3 @@ class MimeResolver {
static String? lookup(String path, {List<int>? headerBytes}) =>
resolver.lookup(path, headerBytes: headerBytes);
}

/// Extension adding an ability to retrieve extension from [MediaType].
extension FileExtensionExt on MediaType {
/// Returns an extension of this [MediaType], if any.
String? get extension {
// TODO: Remove when dart-lang/mime#55 is fixed:
// https://github.com/dart-lang/mime/issues/55
if (mimeType == 'image/jpeg') {
return 'jpg';
}
final fromMime = extensionFromMime(mimeType);
return (fromMime == mimeType) ? null : fromMime;
}
}

0 comments on commit 8a4d16f

Please sign in to comment.