forked from instantiations/es_compression
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f43a80b
Showing
27 changed files
with
2,855 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
# Remove the following pattern if you wish to check in your lock file | ||
pubspec.lock | ||
|
||
# Conventional directory for build outputs | ||
build/ | ||
|
||
# Directory created by dartdoc | ||
doc/api/ | ||
|
||
# IntelliJ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# Mac | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Below is a list of people and organizations that have contributed | ||
# to the project. Names should be added to the list like so: | ||
# | ||
# Name/Organization <email address> | ||
|
||
Instantiations Inc. | ||
Seth Berman <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## 0.1.0 | ||
|
||
- Initial development release, created by Seth Berman [Instantiations, Inc](https://www.instantiations.com). | ||
- Implemented general codec framework. | ||
- Implemented LZ4 FFI bindings (https://github.com/lz4/lz4/tree/v1.9.2). | ||
- Implemented LZ4 codec framework extensions. | ||
- Implemented [LZ4 benchmarks](benchmark/lz4_benchmark.dart) | ||
- Implemented [LZ4 examples](example/lz4_example.dart) | ||
- Implemented [escompress](bin/es_compress.dart) binary with lz4 integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2020, Seth Berman | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
* 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. | ||
* Neither the name of Instantiations, Inc nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
A library for Dart developers. | ||
|
||
Created from templates made available by Stagehand under a BSD-style | ||
[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE). | ||
|
||
## Usage | ||
|
||
A simple usage example: | ||
|
||
```dart | ||
``` | ||
|
||
## Features and bugs | ||
|
||
Please file feature requests and bugs at the [issue tracker][tracker]. | ||
|
||
[tracker]: http://example.com/issues/replaceme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Defines a default set of lint rules enforced for | ||
# projects at Google. For details and rationale, | ||
# see https://github.com/dart-lang/pedantic#enabled-lints. | ||
include: package:pedantic/analysis_options.yaml | ||
|
||
analyzer: | ||
strong-mode: | ||
implicit-casts: false | ||
implicit-dynamic: false | ||
errors: | ||
# treat missing required parameters as a warning (not a hint) | ||
missing_required_param: warning | ||
# treat missing returns as a warning (not a hint) | ||
missing_return: warning | ||
# allow having TODOs in the code | ||
todo: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2020, Seth Berman (Instantiations, Inc). Please see the AUTHORS | ||
// file for details. All rights reserved. Use of this source code is governed by | ||
// a BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
import 'dart:math'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:benchmark_harness/benchmark_harness.dart'; | ||
import 'package:collection/collection.dart'; | ||
import 'package:es_compression/lz4.dart'; | ||
|
||
/// An [Lz4EncodeBenchmark] calls [Lz4Codec.encode] on the incoming data | ||
/// supplied by [Lz4Data]. | ||
/// | ||
/// [warmup] is used to store of the encoded result. | ||
/// [teardown] is used to reassign [Lz4Data.bytes] with the result from this | ||
/// codec. | ||
class Lz4EncodeBenchmark extends BenchmarkBase { | ||
final Lz4Data data; | ||
final Lz4Codec codec; | ||
List<int> encoded; | ||
|
||
Lz4EncodeBenchmark(this.data) | ||
: codec = Lz4Codec(level: -1), | ||
super('lz4 encode()'); | ||
|
||
@override | ||
void warmup() { | ||
encoded = codec.encode(data.bytes); | ||
} | ||
|
||
@override | ||
void exercise() { | ||
codec.encode(data.bytes); | ||
} | ||
|
||
@override | ||
void teardown() { | ||
data.bytes = encoded; | ||
} | ||
} | ||
|
||
/// An [Lz4DecodeBenchmark] calls [Lz4Codec.decode] on the incoming data | ||
/// supplied by [Lz4Data]. | ||
/// | ||
/// [warmup] is used to store of the decoded result. | ||
/// [teardown] is used to reassign [Lz4Data.bytes] with the result from this | ||
/// codec. | ||
class Lz4DecodeBenchmark extends BenchmarkBase { | ||
final Lz4Data data; | ||
final Lz4Codec codec; | ||
List<int> decoded; | ||
|
||
Lz4DecodeBenchmark(this.data) | ||
: codec = Lz4Codec(level: -1), | ||
super('lz4 decode()'); | ||
|
||
@override | ||
void warmup() { | ||
decoded = codec.decode(data.bytes); | ||
} | ||
|
||
@override | ||
void exercise() { | ||
codec.decode(data.bytes); | ||
} | ||
|
||
@override | ||
void teardown() { | ||
data.bytes = decoded; | ||
} | ||
} | ||
|
||
/// Small single-slot container class to flow between benchmarks as data is | ||
/// transformed. | ||
class Lz4Data { | ||
List<int> bytes; | ||
|
||
Lz4Data(this.bytes); | ||
} | ||
|
||
const tutoneConstant = 8675309; | ||
|
||
/// Benchmark: Lz4 Encoding/Decoding of seeded random data. | ||
/// | ||
/// Encoding/Decoding must actually work for the benchmark to be useful. | ||
/// This means the final decoded bytes should match the original input. | ||
/// Verify this and report success (0) if good, failure (-1) if the bytes | ||
/// don't match. | ||
void main() { | ||
// Generate 100MB of seeded pseudo-random bytes to encode/decode | ||
final random = Random(tutoneConstant); | ||
final randomBytes = | ||
List<int>.generate(100 * 1024 * 1024, (i) => random.nextInt(256)); | ||
final data = Lz4Data(Uint8List.fromList(randomBytes)); | ||
|
||
Lz4EncodeBenchmark(data).report(); | ||
Lz4DecodeBenchmark(data).report(); | ||
|
||
final bytesMatch = const ListEquality<int>().equals(randomBytes, data.bytes); | ||
exitCode = (bytesMatch == true) ? 0 : -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2020, Seth Berman (Instantiations, Inc). Please see the AUTHORS | ||
// file for details. All rights reserved. Use of this source code is governed by | ||
// a BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:args/args.dart'; | ||
|
||
const fileNameArg = 'file-name'; | ||
const randomBytesArg = 'random-bytes'; | ||
const levelArg = 'level'; | ||
const streamArg = 'stream'; | ||
|
||
void main(List<String> arguments) { | ||
final argParser = _buildArgParser(); | ||
final argResults = argParser.parse(arguments); | ||
exitCode = 0; | ||
} | ||
|
||
ArgParser _buildArgParser() { | ||
return ArgParser() | ||
..addFlag(streamArg, | ||
help: 'Stream if defined, otherwise convert all at once', | ||
defaultsTo: false, | ||
abbr: 's') | ||
..addOption(fileNameArg, help: 'The filename to encode/decode', abbr: 'f') | ||
..addOption(randomBytesArg, | ||
help: 'The # of random bytes to generate for encode/decode', abbr: 'r') | ||
..addOption(levelArg, help: 'compression level', abbr: 'l'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2020, Seth Berman (Instantiations, Inc). Please see the AUTHORS | ||
// file for details. All rights reserved. Use of this source code is governed by | ||
// a BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
import 'dart:math'; | ||
|
||
import 'package:collection/collection.dart'; | ||
import 'package:es_compression/lz4.dart'; | ||
|
||
const randomByteCount = 256; | ||
const level = -1; | ||
const tutoneConstant = 8675309; | ||
|
||
/// This program demonstrates an lz4 encode/decode of random bytes. | ||
/// | ||
/// The [exitCode] of this script is 0 if the decoded bytes match the original, | ||
/// otherwise the [exitCode] is -1. | ||
void main() { | ||
final random = Random(tutoneConstant); | ||
final randomBytes = | ||
List<int>.generate(randomByteCount, (i) => random.nextInt(256)); | ||
final codec = Lz4Codec(level: level); | ||
|
||
final encoded = codec.encode(randomBytes); | ||
final decoded = codec.decode(encoded); | ||
|
||
final bytesMatch = const ListEquality<int>().equals(randomBytes, decoded); | ||
(bytesMatch == true) ? print('bytes match!') : print('bytes do not match!'); | ||
exitCode = (bytesMatch == true) ? 0 : -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2020, Seth Berman (Instantiations, Inc). Please see the AUTHORS | ||
// file for details. All rights reserved. Use of this source code is governed by | ||
// a BSD-style license that can be found in the LICENSE file. | ||
|
||
export 'src/lz4/codec.dart'; |
Oops, something went wrong.