Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sethloco committed Oct 9, 2020
0 parents commit f43a80b
Show file tree
Hide file tree
Showing 27 changed files with 2,855 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
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
7 changes: 7 additions & 0 deletions AUTHORS
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]>
9 changes: 9 additions & 0 deletions CHANGELOG.md
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
26 changes: 26 additions & 0 deletions LICENSE
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.
18 changes: 18 additions & 0 deletions README.md
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
16 changes: 16 additions & 0 deletions analysis_options.yaml
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
103 changes: 103 additions & 0 deletions benchmark/lz4_benchmark.dart
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;
}
30 changes: 30 additions & 0 deletions bin/es_compress.dart
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');
}
31 changes: 31 additions & 0 deletions example/lz4_example.dart
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;
}
5 changes: 5 additions & 0 deletions lib/lz4.dart
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';
Loading

0 comments on commit f43a80b

Please sign in to comment.