Skip to content

Commit

Permalink
Enabled *.mlpackage models usage. (#814)
Browse files Browse the repository at this point in the history
* updated archive_cached_helper to make possible handle mlpackage zip archive.

* updated lu script to convert mobileBert to the coreml

* updated archive_cache_helper to support mlpackage loading(*.mlpackage.zip)

* code cleanup for archive_cache_helper

* reverted lu.py script

* archive helper code clean
  • Loading branch information
RSMNYS authored Nov 28, 2023
1 parent fc32867 commit e76556c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions flutter/lib/resources/archive_cache_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ class ArchiveCacheHelper {
final archive =
ZipDecoder().decodeBytes(await File(archivePath).readAsBytes());

for (final archiveFile in archive) {
final filePath = '${result.path}/${archiveFile.name}';
final file = await File(filePath).create(recursive: true);

final data = archiveFile.content as List<int>;
await file.writeAsBytes(data);
var archiveParentPath = result.path;
if (!archive.first.isFile) {
archiveParentPath = result.parent.path;
}

for (int i = 0; i < archive.files.length; i++) {
final archiveFile = archive.files[i];
final itemPath = '$archiveParentPath/${archiveFile.name}';
if (archiveFile.isFile) {
final file = await File(itemPath).create(recursive: true);
final data = archiveFile.content as List<int>;
await file.writeAsBytes(data);
} else if (i != 0) {
await Directory(itemPath).create(recursive: true);
}
}
return result;
} catch (e) {
await result.delete(recursive: true);
Expand Down

0 comments on commit e76556c

Please sign in to comment.