Skip to content

Add bsdiff package that implements binary diff/patch algorithm. #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/multicast_dns/lib/src/native_protocol_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ResourceRecordCache {
// Clear the cache for all name/type combinations to be updated.
final Map<int, Set<String>> seenRecordTypes = <int, Set<String>>{};
for (ResourceRecord record in records) {
seenRecordTypes[record.resourceRecordType] ??= Set<String>();
seenRecordTypes[record.resourceRecordType] ??= {};
if (seenRecordTypes[record.resourceRecordType].add(record.name)) {
_cache[record.resourceRecordType] ??=
SplayTreeMap<String, List<ResourceRecord>>();
Expand Down
2 changes: 1 addition & 1 deletion packages/palette_generator/lib/palette_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class PaletteGenerator extends Diagnosticable {
void _selectSwatches() {
final Set<PaletteTarget> allTargets = Set<PaletteTarget>.from(
(targets ?? <PaletteTarget>[]) + PaletteTarget.baseTargets);
final Set<Color> usedColors = Set<Color>();
final Set<Color> usedColors = {};
for (PaletteTarget target in allTargets) {
target._normalizeWeights();
selectedSwatches[target] = _generateScoredTarget(target, usedColors);
Expand Down
3 changes: 3 additions & 0 deletions third_party/packages/bsdiff/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

* Initial Open Source release.
23 changes: 23 additions & 0 deletions third_party/packages/bsdiff/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright 2003-2005 Colin Percival. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
29 changes: 29 additions & 0 deletions third_party/packages/bsdiff/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# BSDiff

[![pub package](https://img.shields.io/pub/v/bsdiff.svg)](
https://pub.dartlang.org/packages/bsdiff)

Binary diff/patch algorithm based on
[bsdiff 4.3](http://www.daemonology.net/bsdiff/) by Colin Percival.
It's very effective at compressesing incremental changes in binaries.

This implementation has the following differences from Colin's code,
to make it easier to read and apply patches in Java and Objective C:

* Using gzip instead of bzip2 because gzip is included in JDK by default
* Using big- instead of little-endian serialization to simplify Java code
* Using two's complement instead of high-bit coding for negatives numbers

## Usage
To use this package, add `bsdiff` as a
[dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).

## Example

Import the library via
``` dart
import 'package:bsdiff/bsdiff.dart';
```

Then use the `bsdiff` and `bspatch` Dart functions in your code. To see how this is done,
check out the [example app](example/main.dart).
23 changes: 23 additions & 0 deletions third_party/packages/bsdiff/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Example script to illustrate how to use the bsdiff package to generate and apply patches.

import 'dart:typed_data';

import 'package:bsdiff/bsdiff.dart';

void main() async {
final Uint8List originalData = Uint8List.fromList(List.generate(1000, (index) => index));
final Uint8List modifiedData = Uint8List.fromList(List.generate(2000, (index) => 2 * index));

print('Original data size ${originalData.length} bytes');
print('Modified data size ${modifiedData.length} bytes');

final Uint8List generatedPatch = bsdiff(originalData, modifiedData);
final Uint8List restoredData = bspatch(originalData, generatedPatch);

print('Generated patch is ${generatedPatch.length} bytes');
print('Restored data size ${restoredData.length} bytes');
}
10 changes: 10 additions & 0 deletions third_party/packages/bsdiff/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: main
description: A simple example of how to use bsdiff to generate and apply patches.
version: 0.1.0

dependencies:
bsdiff:
path: ..

environment:
sdk: ">=2.1.1-dev.2.0 <3.0.0"
Loading