mirror of
https://gitlab.com/TheOneWithTheBraid/dart_pkpass.git
synced 2025-07-06 05:18:47 +00:00
fix: support utf-16 encoding
This commit is contained in:
parent
c1d9fa2db3
commit
6bd3ff3ad9
5 changed files with 27 additions and 24 deletions
|
@ -36,7 +36,10 @@ class PassFile {
|
|||
final file = archive.files
|
||||
.singleWhere((element) => element.name == manifestEntry.key);
|
||||
|
||||
final content = file.byteContent;
|
||||
final content = file.readBytes();
|
||||
if (content == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String hash = sha1.convert(content).toString();
|
||||
|
||||
|
@ -80,7 +83,7 @@ class PassFile {
|
|||
);
|
||||
if (path == null) return null;
|
||||
final file = _folder.singleWhere((element) => element.name == path);
|
||||
final content = file.byteContent;
|
||||
final content = file.readBytes();
|
||||
return content;
|
||||
}
|
||||
|
||||
|
@ -119,29 +122,25 @@ class PassFile {
|
|||
extension on ArchiveFile {
|
||||
String get stringContent {
|
||||
final codec = Charset.detect(
|
||||
byteContent,
|
||||
readBytes()!,
|
||||
defaultEncoding: utf8,
|
||||
orders: [
|
||||
utf8,
|
||||
ascii,
|
||||
gbk,
|
||||
latin1,
|
||||
utf16,
|
||||
],
|
||||
) ??
|
||||
utf8;
|
||||
return codec.decode(content);
|
||||
}
|
||||
|
||||
Uint8List get byteContent {
|
||||
decompress();
|
||||
|
||||
final content = this.content;
|
||||
if (content is String) {
|
||||
return utf8.encode(content);
|
||||
} else if (content is Iterable) {
|
||||
return Uint8List.fromList(content.cast<int>().toList());
|
||||
} else {
|
||||
return rawContent!.toUint8List();
|
||||
try {
|
||||
return codec.decode(content);
|
||||
} on FormatException {
|
||||
// utf8 and utf16 are hard to distinguish
|
||||
if (codec is Utf8Codec) {
|
||||
return utf16.decode(content);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue