Skip to content

Commit

Permalink
fix: Can't decode gbk encoding issue #131
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Mar 31, 2024
1 parent adb9a60 commit 0d3ff0d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_distributor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.9

* fix: Can't decode gbk encoding issue #131

## 0.3.8

* bump `archive` to 3.4.10
Expand Down
1 change: 1 addition & 0 deletions packages/flutter_distributor/README-ZH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../README-ZH.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import 'dart:convert';
import 'dart:io';

import 'package:charset/charset.dart';
import 'package:flutter_distributor/src/extensions/string.dart';
import 'package:flutter_distributor/src/utils/logger.dart';
import 'package:shell_executor/shell_executor.dart';

/// Convert bytes to string (UTF-8 or detected charset)
String convertToString(List<int> bytes) {
final charset = Charset.detect(bytes);
if (charset != null) {
return charset.decode(bytes);
}
return utf8.decode(bytes, allowMalformed: true);
}

class DefaultShellExecutor extends ShellExecutor {
@override
Future<ProcessResult> exec(
Expand All @@ -26,13 +36,13 @@ class DefaultShellExecutor extends ShellExecutor {
String? stdoutStr;
String? stderrStr;

process.stdout.listen((event) {
String msg = utf8.decoder.convert(event);
process.stdout.listen((data) {
String msg = convertToString(data);
stdoutStr = '${stdoutStr ?? ''}$msg';
stdout.write(msg.brightBlack());
});
process.stderr.listen((event) {
String msg = utf8.decoder.convert(event);
process.stderr.listen((data) {
String msg = convertToString(data);
stderrStr = '${stderrStr ?? ''}$msg';
stderr.write(msg.brightRed());
});
Expand Down
8 changes: 8 additions & 0 deletions packages/flutter_distributor/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
charset:
dependency: "direct main"
description:
name: charset
sha256: "27802032a581e01ac565904ece8c8962564b1070690794f0072f6865958ce8b9"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
checked_yaml:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions packages/flutter_distributor/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
app_package_maker: ^0.3.6
app_package_publisher: ^0.3.6
args: ^2.2.0
charset: ^2.0.1
dio: ^5.3.4
flutter_app_builder: ^0.3.7
flutter_app_packager: ^0.3.7
Expand Down

0 comments on commit 0d3ff0d

Please sign in to comment.