Reland #27754, now that bsdiff has moved to flutter/packages. (#28291)

This commit is contained in:
Stanislav Baranov
2019-02-21 21:59:41 -08:00
committed by GitHub
parent d39a72516a
commit 3837ec9e96
34 changed files with 81 additions and 70 deletions

View File

@@ -5,6 +5,7 @@
import 'dart:async';
import 'package:archive/archive.dart';
import 'package:bsdiff/bsdiff.dart';
import 'package:meta/meta.dart';
import '../android/android_sdk.dart';
@@ -499,6 +500,7 @@ Future<void> _buildGradleProjectV2(
throwToolExit('Error: Could not find baseline package ${baselineApkFile.path}.');
printStatus('Found baseline package ${baselineApkFile.path}.');
printStatus('Creating dynamic patch...');
final Archive newApk = ZipDecoder().decodeBytes(apkFile.readAsBytesSync());
final Archive oldApk = ZipDecoder().decodeBytes(baselineApkFile.readAsBytesSync());
@@ -520,7 +522,14 @@ Future<void> _buildGradleProjectV2(
throwToolExit("Error: Dynamic patching doesn't support changes to ${newFile.name}.");
final String name = fs.path.relative(newFile.name, from: 'assets/');
update.addFile(ArchiveFile(name, newFile.content.length, newFile.content));
if (name.contains('_snapshot_')) {
final List<int> diff = bsdiff(oldFile.content, newFile.content);
final int ratio = 100 * diff.length ~/ newFile.content.length;
printStatus('Deflated $name by ${ratio == 0 ? 99 : 100 - ratio}%');
update.addFile(ArchiveFile(name + '.bzdiff40', diff.length, diff));
} else {
update.addFile(ArchiveFile(name, newFile.content.length, newFile.content));
}
}
File updateFile;
@@ -568,7 +577,8 @@ Future<void> _buildGradleProjectV2(
updateFile.parent.createSync(recursive: true);
updateFile.writeAsBytesSync(ZipEncoder().encode(update), flush: true);
printStatus('Created dynamic patch ${updateFile.path}.');
final String patchSize = getSizeAsMB(updateFile.lengthSync());
printStatus('Created dynamic patch ${updateFile.path} ($patchSize).');
}
} else {
final File bundleFile = _findBundleFile(project, buildInfo);

View File

@@ -12,6 +12,7 @@ dependencies:
analyzer: 0.35.1
archive: 2.0.8
args: 1.5.1
bsdiff: 0.1.0
completion: 0.2.1+1
coverage: 0.12.4
crypto: 2.0.6
@@ -75,7 +76,7 @@ dependencies:
matcher: 0.12.3+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
package_resolver: 1.0.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
path: 1.6.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pedantic: 1.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pedantic: 1.5.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
petitparser: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pool: 1.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
protobuf: 0.13.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -98,7 +99,8 @@ dependencies:
dev_dependencies:
collection: 1.14.11
mockito: 4.0.0
file_testing: 2.0.3
file_testing: 2.1.0
test: 1.5.3
vm_service_lib: 3.14.2
http_multi_server: 2.0.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -108,10 +110,9 @@ dev_dependencies:
node_preamble: 1.4.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
shelf_packages_handler: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
shelf_static: 0.2.8 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
test: 1.5.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dartdoc:
# Exclude this package from the hosted API docs.
nodoc: true
# PUBSPEC CHECKSUM: 9759
# PUBSPEC CHECKSUM: b511