TF-2602 Add detect file charset on mobile
This commit is contained in:
@@ -5,9 +5,12 @@ import 'package:core/domain/exceptions/download_file_exception.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_charset_detector/flutter_charset_detector.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class FileUtils {
|
||||
static const String DEFAULT_CHARSET = 'UTF-8';
|
||||
static const String TEXT_PLAIN_MIME_TYPE = 'text/plain';
|
||||
|
||||
Future<String> _getInternalStorageDirPath({
|
||||
required String nameFile,
|
||||
@@ -135,4 +138,16 @@ class FileUtils {
|
||||
logError('$runtimeType::deleteCompressedFileOnMobile: error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getFileCharset(String filePath) async {
|
||||
try {
|
||||
final file = File(filePath);
|
||||
final decodingResult = await CharsetDetector.autoDecode(file.readAsBytesSync());
|
||||
logError('FileUtils::getFileCharset: FILE_CHARSET = ${decodingResult.charset}');
|
||||
return decodingResult.charset;
|
||||
} catch (e) {
|
||||
logError('FileUtils::getFileCharset: Exception: $e');
|
||||
return DEFAULT_CHARSET;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -326,6 +326,38 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_charset_detector:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_charset_detector
|
||||
sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
flutter_charset_detector_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_charset_detector_android
|
||||
sha256: "43d0c0063242d036b873ade737ebae38716af5cd8b2a4df1754adfd186d58e2c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
flutter_charset_detector_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_charset_detector_ios
|
||||
sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
flutter_charset_detector_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_charset_detector_platform_interface
|
||||
sha256: fcb61de27285031164c945aca4b42e4d36f9a9e359212f21ab652275c9c723ec
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
flutter_image_compress:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -79,6 +79,8 @@ dependencies:
|
||||
|
||||
fk_user_agent: 2.1.0
|
||||
|
||||
flutter_charset_detector: 2.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
Reference in New Issue
Block a user