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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user