diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fa3206..e8d31be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.4 + +- Enhanced Android library resolution (special thanks to [mejdi14](https://github.com/mejdi14) for providing this). +- Linter updates and code cleanup + ## 2.0.3 - Updated [prebuilt libraries](lib/src/zstd/blobs) to [ZSTD v1.5.0](https://github.com/facebook/zstd/releases/tag/v1.5.0). diff --git a/LICENSE b/LICENSE index 77eefaf..445901e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2021, Seth Berman (Instantiations, Inc) +Copyright (c) 2022, Seth Berman (Instantiations, Inc) All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/analysis_options.yaml b/analysis_options.yaml index 573a899..948b828 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,7 +1,7 @@ # 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 +include: package:lints/recommended.yaml analyzer: strong-mode: @@ -17,5 +17,61 @@ analyzer: linter: rules: - # in conflict with effective-dart rules - avoid_types_on_closure_parameters: false \ No newline at end of file + - avoid_catching_errors + - avoid_dynamic_calls + - avoid_function_literals_in_foreach_calls + - avoid_private_typedef_functions + - avoid_renaming_method_parameters + - avoid_returning_null_for_void + - avoid_unused_constructor_parameters + - avoid_void_async + - await_only_futures + - camel_case_types + - cancel_subscriptions + - comment_references + - constant_identifier_names + - control_flow_in_finally + - directives_ordering + - empty_statements + - file_names + - hash_and_equals + - implementation_imports + - iterable_contains_unrelated_type + - join_return_with_assignment + - lines_longer_than_80_chars + - list_remove_unrelated_type + - missing_whitespace_between_adjacent_strings + - no_runtimeType_toString + - non_constant_identifier_names + - only_throw_errors + - overridden_fields + - package_api_docs + - package_names + - package_prefixed_library_names + - prefer_asserts_in_initializer_lists + - prefer_const_constructors + - prefer_const_declarations + - prefer_expression_function_bodies + - prefer_final_locals + - prefer_function_declarations_over_variables + - prefer_initializing_formals + - prefer_inlined_adds + - prefer_interpolation_to_compose_strings + - prefer_is_not_operator + - prefer_null_aware_operators + - prefer_relative_imports + - prefer_typing_uninitialized_variables + - prefer_void_to_null + - provide_deprecation_message + - sort_pub_dependencies + - test_types_in_equals + - throw_in_finally + - unnecessary_brace_in_string_interps + - unnecessary_lambdas + - unnecessary_null_aware_assignments + - unnecessary_overrides + - unnecessary_parenthesis + - unnecessary_statements + - unnecessary_string_interpolations + - use_string_buffers + - void_checks \ No newline at end of file diff --git a/benchmark/brotli_benchmark.dart b/benchmark/brotli_benchmark.dart index 45cf102..3744036 100644 --- a/benchmark/brotli_benchmark.dart +++ b/benchmark/brotli_benchmark.dart @@ -2,8 +2,6 @@ // 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:benchmark_harness/benchmark_harness.dart'; import 'package:collection/collection.dart'; import 'package:es_compression/brotli.dart'; @@ -11,7 +9,7 @@ import 'package:es_compression/framework.dart'; import 'utils/benchmark_utils.dart'; -/// An [BrotliEncodeBenchmark] calls [BrotliCodec.encode] on the incoming data +/// An [BrotliEncodeBenchmark] calls [BrotliCodec.encode()] on the incoming data /// supplied by [BrotliData]. /// /// [warmup] is used to store of the encoded result. @@ -48,7 +46,7 @@ class BrotliEncodeBenchmark extends BenchmarkBase { } } -/// An [BrotliDecodeBenchmark] calls [BrotliCodec.decode] on the incoming data +/// An [BrotliDecodeBenchmark] calls [BrotliCodec.decode()] on the incoming data /// supplied by [BrotliData]. /// /// [warmup] is used to store of the decoded result. @@ -102,37 +100,34 @@ class BrotliData { Future main(List arguments) async { final dataLength = arguments.isEmpty ? 50 * 1024 * 1024 : int.parse(arguments.first); - exitCode = await _runBrotliBenchmark(dataLength); - return exitCode; + return await _runBrotliBenchmark(dataLength); } /// Brotli Benchmark which answers 0 on success, -1 on error -Future _runBrotliBenchmark(int dataLength) async { - return Future(() { - print('generating $dataLength bytes of random data'); - final bytes = generateRandomBytes(dataLength); - final emitter = CodecPerformanceEmitter(bytes.length); - - print('Brotli encode/decode ${bytes.length} bytes of random data.'); - var data = BrotliData(bytes); - BrotliEncodeBenchmark(data, emitter: emitter).report(); - print('compression ratio: ' - '${compressionRatio(bytes.length, data.bytes.length)}'); - BrotliDecodeBenchmark(data, emitter: emitter).report(); - var bytesMatch = const ListEquality().equals(bytes, data.bytes); - if (bytesMatch != true) return -1; - - print(''); - print('generating ${bytes.length} bytes of constant data'); - bytes.fillRange(0, bytes.length, 1); - - print('Brotli encode/decode ${bytes.length} bytes of constant data.'); - data = BrotliData(bytes); - BrotliEncodeBenchmark(data, emitter: emitter).report(); - print('compression ratio: ' - '${compressionRatio(bytes.length, data.bytes.length)}'); - BrotliDecodeBenchmark(data, emitter: emitter).report(); - bytesMatch = const ListEquality().equals(bytes, data.bytes); - return (bytesMatch != true) ? -1 : 0; - }); -} +Future _runBrotliBenchmark(int dataLength) async => Future(() { + print('generating $dataLength bytes of random data'); + final bytes = generateRandomBytes(dataLength); + final emitter = CodecPerformanceEmitter(bytes.length); + + print('Brotli encode/decode ${bytes.length} bytes of random data.'); + var data = BrotliData(bytes); + BrotliEncodeBenchmark(data, emitter: emitter).report(); + print('compression ratio: ' + '${compressionRatio(bytes.length, data.bytes.length)}'); + BrotliDecodeBenchmark(data, emitter: emitter).report(); + var bytesMatch = const ListEquality().equals(bytes, data.bytes); + if (bytesMatch != true) return -1; + + print(''); + print('generating ${bytes.length} bytes of constant data'); + bytes.fillRange(0, bytes.length, 1); + + print('Brotli encode/decode ${bytes.length} bytes of constant data.'); + data = BrotliData(bytes); + BrotliEncodeBenchmark(data, emitter: emitter).report(); + print('compression ratio: ' + '${compressionRatio(bytes.length, data.bytes.length)}'); + BrotliDecodeBenchmark(data, emitter: emitter).report(); + bytesMatch = const ListEquality().equals(bytes, data.bytes); + return (bytesMatch != true) ? -1 : 0; + }); diff --git a/benchmark/gzip_benchmark.dart b/benchmark/gzip_benchmark.dart index 9ffdc89..1243fbe 100644 --- a/benchmark/gzip_benchmark.dart +++ b/benchmark/gzip_benchmark.dart @@ -6,11 +6,10 @@ import 'dart:io'; import 'package:benchmark_harness/benchmark_harness.dart'; import 'package:collection/collection.dart'; -import 'package:es_compression/framework.dart'; import 'utils/benchmark_utils.dart'; -/// An [GZipEncodeBenchmark] calls [GZipCodec.encode] on the incoming data +/// An [GZipEncodeBenchmark] calls [GZipCodec.encode()] on the incoming data /// supplied by [GZipData]. /// /// [warmup] is used to store of the encoded result. @@ -21,10 +20,7 @@ class GZipEncodeBenchmark extends BenchmarkBase { final GZipCodec codec; late List encoded; - GZipEncodeBenchmark(this.data, - {ScoreEmitter emitter = const PrintEmitter(), - int inputBufferLength = CodecBufferHolder.autoLength, - int outputBufferLength = CodecBufferHolder.autoLength}) + GZipEncodeBenchmark(this.data, {ScoreEmitter emitter = const PrintEmitter()}) : codec = GZipCodec(level: -1), super('gzip encode()', emitter: emitter); @@ -44,7 +40,7 @@ class GZipEncodeBenchmark extends BenchmarkBase { } } -/// An [GZipDecodeBenchmark] calls [GZipCodec.decode] on the incoming data +/// An [GZipDecodeBenchmark] calls [GZipCodec.decode()] on the incoming data /// supplied by [GZipData]. /// /// [warmup] is used to store of the decoded result. @@ -55,10 +51,7 @@ class GZipDecodeBenchmark extends BenchmarkBase { final GZipCodec codec; late List decoded; - GZipDecodeBenchmark(this.data, - {ScoreEmitter emitter = const PrintEmitter(), - int inputBufferLength = CodecBufferHolder.autoLength, - int outputBufferLength = CodecBufferHolder.autoLength}) + GZipDecodeBenchmark(this.data, {ScoreEmitter emitter = const PrintEmitter()}) : codec = GZipCodec(level: -1), super('gzip decode()', emitter: emitter); @@ -95,37 +88,34 @@ class GZipData { Future main(List arguments) async { final dataLength = arguments.isEmpty ? 50 * 1024 * 1024 : int.parse(arguments.first); - exitCode = await _runGZipBenchmark(dataLength); - return exitCode; + return await _runGZipBenchmark(dataLength); } /// GZip Benchmark which answers 0 on success, -1 on error -Future _runGZipBenchmark(int dataLength) async { - return Future(() { - print('generating $dataLength bytes of random data'); - final bytes = generateRandomBytes(dataLength); - final emitter = CodecPerformanceEmitter(bytes.length); - - print('GZip encode/decode ${bytes.length} bytes of random data.'); - var data = GZipData(bytes); - GZipEncodeBenchmark(data, emitter: emitter).report(); - print('compression ratio:' - '${compressionRatio(bytes.length, data.bytes.length)}'); - GZipDecodeBenchmark(data, emitter: emitter).report(); - var bytesMatch = const ListEquality().equals(bytes, data.bytes); - if (bytesMatch != true) return -1; - - print(''); - print('generating ${bytes.length} bytes of constant data'); - bytes.fillRange(0, bytes.length, 1); - - print('GZip encode/decode ${bytes.length} bytes of constant data.'); - data = GZipData(bytes); - GZipEncodeBenchmark(data, emitter: emitter).report(); - print('compression ratio: ' - '${compressionRatio(bytes.length, data.bytes.length)}'); - GZipDecodeBenchmark(data, emitter: emitter).report(); - bytesMatch = const ListEquality().equals(bytes, data.bytes); - return (bytesMatch != true) ? -1 : 0; - }); -} +Future _runGZipBenchmark(int dataLength) async => Future(() { + print('generating $dataLength bytes of random data'); + final bytes = generateRandomBytes(dataLength); + final emitter = CodecPerformanceEmitter(bytes.length); + + print('GZip encode/decode ${bytes.length} bytes of random data.'); + var data = GZipData(bytes); + GZipEncodeBenchmark(data, emitter: emitter).report(); + print('compression ratio:' + '${compressionRatio(bytes.length, data.bytes.length)}'); + GZipDecodeBenchmark(data, emitter: emitter).report(); + var bytesMatch = const ListEquality().equals(bytes, data.bytes); + if (bytesMatch != true) return -1; + + print(''); + print('generating ${bytes.length} bytes of constant data'); + bytes.fillRange(0, bytes.length, 1); + + print('GZip encode/decode ${bytes.length} bytes of constant data.'); + data = GZipData(bytes); + GZipEncodeBenchmark(data, emitter: emitter).report(); + print('compression ratio: ' + '${compressionRatio(bytes.length, data.bytes.length)}'); + GZipDecodeBenchmark(data, emitter: emitter).report(); + bytesMatch = const ListEquality().equals(bytes, data.bytes); + return (bytesMatch != true) ? -1 : 0; + }); diff --git a/benchmark/lz4_benchmark.dart b/benchmark/lz4_benchmark.dart index fa0f0f9..a6cafdf 100644 --- a/benchmark/lz4_benchmark.dart +++ b/benchmark/lz4_benchmark.dart @@ -2,8 +2,6 @@ // 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:benchmark_harness/benchmark_harness.dart'; import 'package:collection/collection.dart'; import 'package:es_compression/framework.dart'; @@ -11,7 +9,7 @@ import 'package:es_compression/lz4.dart'; import 'utils/benchmark_utils.dart'; -/// An [Lz4EncodeBenchmark] calls [Lz4Codec.encode] on the incoming data +/// An [Lz4EncodeBenchmark] calls [Lz4Codec.encode()] on the incoming data /// supplied by [Lz4Data]. /// /// [warmup] is used to store of the encoded result. @@ -48,7 +46,7 @@ class Lz4EncodeBenchmark extends BenchmarkBase { } } -/// An [Lz4DecodeBenchmark] calls [Lz4Codec.decode] on the incoming data +/// An [Lz4DecodeBenchmark] calls [Lz4Codec.decode()] on the incoming data /// supplied by [Lz4Data]. /// /// [warmup] is used to store of the decoded result. @@ -102,37 +100,34 @@ class Lz4Data { Future main(List arguments) async { final dataLength = arguments.isEmpty ? 50 * 1024 * 1024 : int.parse(arguments.first); - exitCode = await _runLz4Benchmark(dataLength); - return exitCode; + return await _runLz4Benchmark(dataLength); } /// Lz4 Benchmark which answers 0 on success, -1 on error -Future _runLz4Benchmark(int dataLength) async { - return Future(() { - print('generating $dataLength bytes of random data'); - final bytes = generateRandomBytes(dataLength); - final emitter = CodecPerformanceEmitter(bytes.length); - - print('Lz4 encode/decode ${bytes.length} bytes of random data.'); - var data = Lz4Data(bytes); - Lz4EncodeBenchmark(data, emitter: emitter).report(); - print('compression ratio: ' - '${compressionRatio(bytes.length, data.bytes.length)}'); - Lz4DecodeBenchmark(data, emitter: emitter).report(); - var bytesMatch = const ListEquality().equals(bytes, data.bytes); - if (bytesMatch != true) return -1; - - print(''); - print('generating ${bytes.length} bytes of constant data'); - bytes.fillRange(0, bytes.length, 1); - - print('Lz4 encode/decode ${bytes.length} bytes of constant data.'); - data = Lz4Data(bytes); - Lz4EncodeBenchmark(data, emitter: emitter).report(); - print('compression ratio: ' - '${compressionRatio(bytes.length, data.bytes.length)}'); - Lz4DecodeBenchmark(data, emitter: emitter).report(); - bytesMatch = const ListEquality().equals(bytes, data.bytes); - return (bytesMatch != true) ? -1 : 0; - }); -} +Future _runLz4Benchmark(int dataLength) async => Future(() { + print('generating $dataLength bytes of random data'); + final bytes = generateRandomBytes(dataLength); + final emitter = CodecPerformanceEmitter(bytes.length); + + print('Lz4 encode/decode ${bytes.length} bytes of random data.'); + var data = Lz4Data(bytes); + Lz4EncodeBenchmark(data, emitter: emitter).report(); + print('compression ratio: ' + '${compressionRatio(bytes.length, data.bytes.length)}'); + Lz4DecodeBenchmark(data, emitter: emitter).report(); + var bytesMatch = const ListEquality().equals(bytes, data.bytes); + if (bytesMatch != true) return -1; + + print(''); + print('generating ${bytes.length} bytes of constant data'); + bytes.fillRange(0, bytes.length, 1); + + print('Lz4 encode/decode ${bytes.length} bytes of constant data.'); + data = Lz4Data(bytes); + Lz4EncodeBenchmark(data, emitter: emitter).report(); + print('compression ratio: ' + '${compressionRatio(bytes.length, data.bytes.length)}'); + Lz4DecodeBenchmark(data, emitter: emitter).report(); + bytesMatch = const ListEquality().equals(bytes, data.bytes); + return (bytesMatch != true) ? -1 : 0; + }); diff --git a/benchmark/utils/benchmark_utils.dart b/benchmark/utils/benchmark_utils.dart index f3e9a7c..738a995 100644 --- a/benchmark/utils/benchmark_utils.dart +++ b/benchmark/utils/benchmark_utils.dart @@ -6,8 +6,8 @@ import 'package:benchmark_harness/benchmark_harness.dart'; /// Constant used for RNG seed const tutoneConstant = 8675309; -/// [Emitter] which prints total time in milliseconds, as well as the calculated -/// MB/sec based on the length of the uncompressed data. +/// [ScoreEmitter] which prints total time in milliseconds, as well as the +/// calculated MB/sec based on the length of the uncompressed data. class CodecPerformanceEmitter implements ScoreEmitter { final int dataLength; @@ -41,6 +41,5 @@ List generateConstantBytes(int length) { return list; } -String compressionRatio(int uLength, int cLength) { - return '${(uLength / cLength).toStringAsFixed(1)}:1'; -} +String compressionRatio(int uLength, int cLength) => + '${(uLength / cLength).toStringAsFixed(1)}:1'; diff --git a/benchmark/zstd_benchmark.dart b/benchmark/zstd_benchmark.dart index 594ad61..6784795 100644 --- a/benchmark/zstd_benchmark.dart +++ b/benchmark/zstd_benchmark.dart @@ -2,8 +2,6 @@ // 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:benchmark_harness/benchmark_harness.dart'; import 'package:collection/collection.dart'; import 'package:es_compression/framework.dart'; @@ -11,7 +9,7 @@ import 'package:es_compression/zstd.dart'; import 'utils/benchmark_utils.dart'; -/// An [ZstdEncodeBenchmark] calls [ZstdCodec.encode] on the incoming data +/// An [ZstdEncodeBenchmark] calls [ZstdCodec.encode()] on the incoming data /// supplied by [ZstdData]. /// /// [warmup] is used to store of the encoded result. @@ -48,7 +46,7 @@ class ZstdEncodeBenchmark extends BenchmarkBase { } } -/// An [ZstdDecodeBenchmark] calls [ZstdCodec.decode] on the incoming data +/// An [ZstdDecodeBenchmark] calls [ZstdCodec.decode()] on the incoming data /// supplied by [ZstdData]. /// /// [warmup] is used to store of the decoded result. @@ -102,37 +100,34 @@ class ZstdData { Future main(List arguments) async { final dataLength = arguments.isEmpty ? 50 * 1024 * 1024 : int.parse(arguments.first); - exitCode = await _runZstdBenchmark(dataLength); - return exitCode; + return await _runZstdBenchmark(dataLength); } /// Zstd Benchmark which answers 0 on success, -1 on error -Future _runZstdBenchmark(int dataLength) async { - return Future(() { - print('generating $dataLength bytes of random data'); - final bytes = generateRandomBytes(dataLength); - final emitter = CodecPerformanceEmitter(bytes.length); - - print('Zstd encode/decode ${bytes.length} bytes of random data.'); - var data = ZstdData(bytes); - ZstdEncodeBenchmark(data, emitter: emitter).report(); - print('compression ratio: ' - '${compressionRatio(bytes.length, data.bytes.length)}'); - ZstdDecodeBenchmark(data, emitter: emitter).report(); - var bytesMatch = const ListEquality().equals(bytes, data.bytes); - if (bytesMatch != true) return -1; - - print(''); - print('generating ${bytes.length} bytes of constant data'); - bytes.fillRange(0, bytes.length, 1); - - print('Zstd encode/decode ${bytes.length} bytes of constant data.'); - data = ZstdData(bytes); - ZstdEncodeBenchmark(data, emitter: emitter).report(); - print('compression ratio: ' - '${compressionRatio(bytes.length, data.bytes.length)}'); - ZstdDecodeBenchmark(data, emitter: emitter).report(); - bytesMatch = const ListEquality().equals(bytes, data.bytes); - return (bytesMatch != true) ? -1 : 0; - }); -} +Future _runZstdBenchmark(int dataLength) async => Future(() { + print('generating $dataLength bytes of random data'); + final bytes = generateRandomBytes(dataLength); + final emitter = CodecPerformanceEmitter(bytes.length); + + print('Zstd encode/decode ${bytes.length} bytes of random data.'); + var data = ZstdData(bytes); + ZstdEncodeBenchmark(data, emitter: emitter).report(); + print('compression ratio: ' + '${compressionRatio(bytes.length, data.bytes.length)}'); + ZstdDecodeBenchmark(data, emitter: emitter).report(); + var bytesMatch = const ListEquality().equals(bytes, data.bytes); + if (bytesMatch != true) return -1; + + print(''); + print('generating ${bytes.length} bytes of constant data'); + bytes.fillRange(0, bytes.length, 1); + + print('Zstd encode/decode ${bytes.length} bytes of constant data.'); + data = ZstdData(bytes); + ZstdEncodeBenchmark(data, emitter: emitter).report(); + print('compression ratio: ' + '${compressionRatio(bytes.length, data.bytes.length)}'); + ZstdDecodeBenchmark(data, emitter: emitter).report(); + bytesMatch = const ListEquality().equals(bytes, data.bytes); + return (bytesMatch != true) ? -1 : 0; + }); diff --git a/bin/es_compress.dart b/bin/es_compress.dart index 79c3a12..7cfbe55 100644 --- a/bin/es_compress.dart +++ b/bin/es_compress.dart @@ -111,8 +111,7 @@ Future main(List arguments) async { }, cancelOnError: true); } - exitCode = await exited; - return exitCode; + return await exited; } /// Return true if encoding, false if decoding. diff --git a/example/brotli_example.dart b/example/brotli_example.dart index 8c4905d..c676559 100644 --- a/example/brotli_example.dart +++ b/example/brotli_example.dart @@ -16,10 +16,7 @@ const level = 0; /// /// The [exitCode] of this script is 0 if the decoded bytes match the original, /// otherwise the [exitCode] is -1. -Future main() async { - exitCode = await _runBrotliExample(); - return exitCode; -} +Future main() async => await _runBrotliExample(); /// Brotli Example which answers 0 on success, -1 on error Future _runBrotliExample() async { diff --git a/example/lz4_example.dart b/example/lz4_example.dart index 01491f9..5ecc712 100644 --- a/example/lz4_example.dart +++ b/example/lz4_example.dart @@ -16,10 +16,7 @@ const level = -1; /// /// The [exitCode] of this script is 0 if the decoded bytes match the original, /// otherwise the [exitCode] is -1. -Future main() async { - exitCode = await _runLz4Example(); - return exitCode; -} +Future main() async => await _runLz4Example(); /// Lz4 Example which answers 0 on success, -1 on error Future _runLz4Example() async { diff --git a/example/rle_example.dart b/example/rle_example.dart index 3803daf..7ea9650 100644 --- a/example/rle_example.dart +++ b/example/rle_example.dart @@ -26,10 +26,7 @@ import 'utils/example_utils.dart'; /// /// The [exitCode] of this script is 0 if the decoded bytes match the original, /// otherwise the [exitCode] is -1. -Future main() async { - exitCode = await _runRleExample(); - return exitCode; -} +Future main() async => await _runRleExample(); /// Rle Example which answers 0 on success, -1 on error Future _runRleExample() async { diff --git a/example/utils/example_utils.dart b/example/utils/example_utils.dart index bc48122..dd04041 100644 --- a/example/utils/example_utils.dart +++ b/example/utils/example_utils.dart @@ -27,9 +27,9 @@ bool verifyEquality(List list1, List list2, {String header = ''}) { /// Split [list] into [chunkCount] parts. /// Any remainder will be added to the final bucket. List> splitIntoChunks(List list, int chunkCount) { - var chunks = >[]; - var perPart = list.length ~/ chunkCount; - var leftOver = list.length.remainder(chunkCount); + final chunks = >[]; + final perPart = list.length ~/ chunkCount; + final leftOver = list.length.remainder(chunkCount); for (var i = 0, j = 0; i < chunkCount; i++, j += perPart) { chunks.add(list.sublist( j, i + 1 == chunkCount ? j + perPart + leftOver : j + perPart)); diff --git a/example/zstd_example.dart b/example/zstd_example.dart index 4d6f3fd..cf41e1d 100644 --- a/example/zstd_example.dart +++ b/example/zstd_example.dart @@ -16,10 +16,7 @@ const level = -1; /// /// The [exitCode] of this script is 0 if the decoded bytes match the original, /// otherwise the [exitCode] is -1. -Future main() async { - exitCode = await _runZstdExample(); - return exitCode; -} +Future main() async => await _runZstdExample(); /// Zstd Example which answers 0 on success, -1 on error Future _runZstdExample() async { diff --git a/lib/src/brotli/codec.dart b/lib/src/brotli/codec.dart index ede7b7f..decf1f7 100644 --- a/lib/src/brotli/codec.dart +++ b/lib/src/brotli/codec.dart @@ -93,7 +93,7 @@ class BrotliCodec extends Codec, List> { final int outputBufferLength; /// Return the base binding version this binding code was developed for. - BrotliVersion get bindingVersion => BrotliVersion(0x1000009); + BrotliVersion get bindingVersion => const BrotliVersion(0x1000009); /// Return the encoder library version. BrotliVersion get encoderVersion => BrotliVersion(encoderVersionNumber); @@ -141,11 +141,11 @@ class BrotliCodec extends Codec, List> { inputBufferLength = CodecBufferHolder.autoLength, outputBufferLength = CodecBufferHolder.autoLength; - /// Return the [BrotliEncoder] configured implementation. + /// Return the brotli encoder configured implementation. @override Converter, List> get encoder => encoderImpl; - /// Return the [BrotliDecoder] configured implementation. + /// Return the brotli decoder configured implementation. @override Converter, List> get decoder => decoderImpl; } diff --git a/lib/src/brotli/decoder.dart b/lib/src/brotli/decoder.dart index b8335ad..096b9ea 100644 --- a/lib/src/brotli/decoder.dart +++ b/lib/src/brotli/decoder.dart @@ -17,8 +17,7 @@ const brotliDecoderInputBufferLength = 64 * 1024; /// Default output buffer length. const brotliDecoderOutputBufferLength = brotliDecoderInputBufferLength; -/// The [BrotliDecoder] decoder is used by [BrotliCodec] to decompress brotli -/// data. +/// The [BrotliDecoder] decoder is used to decompress brotli data. class BrotliDecoder extends CodecConverter { /// Flag the determines if "canny" ring buffer allocation is enabled. /// Ring buffer is allocated according to window size, despite the real size @@ -73,7 +72,7 @@ class _BrotliDecoderSink extends CodecSink { /// There is a conditional import that determines the implementation of /// [BrotliDecompressFilter] based on the environment. CodecFilter _makeBrotliDecompressFilter( - bool ringBufferReallocation, bool largeWindow) { - return BrotliDecompressFilter( - ringBufferReallocation: ringBufferReallocation, largeWindow: largeWindow); -} + bool ringBufferReallocation, bool largeWindow) => + BrotliDecompressFilter( + ringBufferReallocation: ringBufferReallocation, + largeWindow: largeWindow); diff --git a/lib/src/brotli/encoder.dart b/lib/src/brotli/encoder.dart index f946db0..1a37f6e 100644 --- a/lib/src/brotli/encoder.dart +++ b/lib/src/brotli/encoder.dart @@ -19,8 +19,7 @@ const brotliEncoderInputBufferLength = 64 * 1024; /// Default output buffer length. const brotliEncoderOutputBufferLength = brotliEncoderInputBufferLength; -/// The [BrotliEncoder] encoder is used by [BrotliCodec] to brotli compress -/// data. +/// The [BrotliEncoder] encoder is used to brotli compress data. class BrotliEncoder extends CodecConverter { /// The compression-[level] or quality can be set in the range of /// [BrotliOption.minLevel]..[BrotliOption.maxLevel]. @@ -165,27 +164,26 @@ class _BrotliEncoderSink extends CodecSink { /// There is a conditional import that determines the implementation of /// [BrotliCompressFilter] based on the environment. CodecFilter _makeBrotliCompressFilter( - int level, - int mode, - int windowBits, - int? blockBits, - int? postfixBits, - bool literalContextModeling, - int sizeHint, - bool largeWindow, - int? directDistanceCodeCount, - int inputBufferLength, - int outputBufferLength) { - return BrotliCompressFilter( - level: level, - mode: mode, - windowBits: windowBits, - blockBits: blockBits, - postfixBits: postfixBits, - literalContextModeling: literalContextModeling, - sizeHint: sizeHint, - largeWindow: largeWindow, - directDistanceCodeCount: directDistanceCodeCount, - inputBufferLength: inputBufferLength, - outputBufferLength: outputBufferLength); -} + int level, + int mode, + int windowBits, + int? blockBits, + int? postfixBits, + bool literalContextModeling, + int sizeHint, + bool largeWindow, + int? directDistanceCodeCount, + int inputBufferLength, + int outputBufferLength) => + BrotliCompressFilter( + level: level, + mode: mode, + windowBits: windowBits, + blockBits: blockBits, + postfixBits: postfixBits, + literalContextModeling: literalContextModeling, + sizeHint: sizeHint, + largeWindow: largeWindow, + directDistanceCodeCount: directDistanceCodeCount, + inputBufferLength: inputBufferLength, + outputBufferLength: outputBufferLength); diff --git a/lib/src/brotli/ffi/compress_filter.dart b/lib/src/brotli/ffi/compress_filter.dart index dabd5ec..cf7332f 100644 --- a/lib/src/brotli/ffi/compress_filter.dart +++ b/lib/src/brotli/ffi/compress_filter.dart @@ -60,8 +60,8 @@ class BrotliCompressFilter extends NativeCodecFilterBase { /// Init the filter. /// /// Provide appropriate buffer lengths to codec builders - /// [inputBufferHolder.length] decoding buffer length and - /// [outputBufferHolder.length] encoding buffer length. + /// [inputBufferHolder] decoding buffer length and + /// [outputBufferHolder] encoding buffer length. @override int doInit( CodecBufferHolder, NativeCodecBuffer> inputBufferHolder, @@ -76,7 +76,7 @@ class BrotliCompressFilter extends NativeCodecFilterBase { } // Formula from 'BROTLI_CStreamOutSize' - final outputLength = brotliEncoderOutputBufferLength; + const outputLength = brotliEncoderOutputBufferLength; outputBufferHolder.length = outputBufferHolder.isLengthSet() ? max(outputBufferHolder.length, outputLength) : outputLength; @@ -84,9 +84,9 @@ class BrotliCompressFilter extends NativeCodecFilterBase { return 0; } - /// Perform an brotli encoding of [inputBuffer.unreadCount] bytes in + /// Perform an brotli encoding of `inputBuffer.unreadCount` bytes in /// and put the resulting encoded bytes into [outputBuffer] of length - /// [outputBuffer.unwrittenCount]. + /// `outputBuffer.unwrittenCount`. /// /// Return an [CodecResult] which describes the amount read/write. @override @@ -135,7 +135,7 @@ class BrotliCompressFilter extends NativeCodecFilterBase { outputBuffer.unwrittenCount, outputBuffer.writePtr); if (!_dispatcher.callBrotliEncoderIsFinished(_brotliState)) { - throw FormatException('Failure to finish the stream'); + throw const FormatException('Failure to finish the stream'); } state = CodecFilterState.finalized; final written = result[1]; diff --git a/lib/src/brotli/ffi/decompress_filter.dart b/lib/src/brotli/ffi/decompress_filter.dart index bd550df..cc9b900 100644 --- a/lib/src/brotli/ffi/decompress_filter.dart +++ b/lib/src/brotli/ffi/decompress_filter.dart @@ -46,16 +46,15 @@ class BrotliDecompressFilter extends NativeCodecFilterBase { /// Return [:true:] if there is more data to process, [:false:] otherwise. @override - bool hasMoreToProcess() { - return super.hasMoreToProcess() || - _dispatcher.callBrotliDecoderHasMoreOutput(_brotliState); - } + bool hasMoreToProcess() => + super.hasMoreToProcess() || + _dispatcher.callBrotliDecoderHasMoreOutput(_brotliState); /// Init the filter. /// /// Provide appropriate buffer lengths to codec builders - /// [inputBufferHolder.length] decoding buffer length and - /// [outputBufferHolder.length] encoding buffer length. + /// [inputBufferHolder] decoding buffer length and + /// [outputBufferHolder] encoding buffer length. @override int doInit( CodecBufferHolder, NativeCodecBuffer> inputBufferHolder, @@ -99,7 +98,7 @@ class BrotliDecompressFilter extends NativeCodecFilterBase { @override int doFinalize(CodecBuffer outputBuffer) { if (!_dispatcher.callBrotliDecoderIsFinished(_brotliState)) { - throw FormatException('Failure to finish decoding'); + throw const FormatException('Failure to finish decoding'); } return 0; } diff --git a/lib/src/brotli/ffi/dispatcher.dart b/lib/src/brotli/ffi/dispatcher.dart index b4dee83..1ff88d6 100644 --- a/lib/src/brotli/ffi/dispatcher.dart +++ b/lib/src/brotli/ffi/dispatcher.dart @@ -100,9 +100,8 @@ class BrotliDispatcher with BrotliDispatchErrorCheckerMixin { void callBrotliEncoderDestroyInstance(Pointer state) => library.brotliEncoderDestroyInstance(state); - int callBrotliEncoderMaxCompressedSize(int uncompressedSize) { - return library.brotliEncoderMaxCompressedSize(uncompressedSize); - } + int callBrotliEncoderMaxCompressedSize(int uncompressedSize) => + library.brotliEncoderMaxCompressedSize(uncompressedSize); List callBrotliEncoderCompressStream( Pointer state, @@ -130,35 +129,29 @@ class BrotliDispatcher with BrotliDispatchErrorCheckerMixin { if (ret == BrotliConstants.BROTLI_FALSE) { switch (op) { case BrotliConstants.BROTLI_OPERATION_FINISH: - throw FormatException('BrotliEncoderCompressStream' + throw const FormatException('BrotliEncoderCompressStream' 'failure while finishing the stream'); case BrotliConstants.BROTLI_OPERATION_FLUSH: - throw FormatException('BrotliEncoderCompressStream' + throw const FormatException('BrotliEncoderCompressStream' 'failure while flushing the stream'); case BrotliConstants.BROTLI_OPERATION_PROCESS: - throw FormatException('BrotliEncoderCompressStream' + throw const FormatException('BrotliEncoderCompressStream' 'failure while processing the stream'); default: - throw FormatException('BrotliEncoderCompressStream' + throw const FormatException('BrotliEncoderCompressStream' 'failure'); } } } - bool callBrotliEncoderIsFinished(Pointer state) { - return library.brotliEncoderIsFinished(state) == - BrotliConstants.BROTLI_TRUE; - } + bool callBrotliEncoderIsFinished(Pointer state) => + library.brotliEncoderIsFinished(state) == BrotliConstants.BROTLI_TRUE; - bool callBrotliDecoderIsFinished(Pointer state) { - return library.brotliDecoderIsFinished(state) == - BrotliConstants.BROTLI_TRUE; - } + bool callBrotliDecoderIsFinished(Pointer state) => + library.brotliDecoderIsFinished(state) == BrotliConstants.BROTLI_TRUE; - bool callBrotliDecoderHasMoreOutput(Pointer state) { - return library.brotliDecoderHasMoreOutput(state) == - BrotliConstants.BROTLI_TRUE; - } + bool callBrotliDecoderHasMoreOutput(Pointer state) => + library.brotliDecoderHasMoreOutput(state) == BrotliConstants.BROTLI_TRUE; List callBrotliDecoderDecompressStream( Pointer state, @@ -179,7 +172,7 @@ class BrotliDispatcher with BrotliDispatchErrorCheckerMixin { switch (result) { case BrotliConstants.BROTLI_DECODER_RESULT_SUCCESS: if (remainingIn > 0) { - throw FormatException('$cFunctionName failed. Excessive input'); + throw const FormatException('$cFunctionName failed. Excessive input'); } break; case BrotliConstants.BROTLI_DECODER_RESULT_ERROR: @@ -215,14 +208,12 @@ class BrotliDispatcher with BrotliDispatchErrorCheckerMixin { } Pointer callBrotliDecoderTakeOutput( - Pointer state, Pointer size) { - return library.brotliDecoderTakeOutput(state, size); - } + Pointer state, Pointer size) => + library.brotliDecoderTakeOutput(state, size); Pointer callBrotliEncoderTakeOutput( - Pointer state, Pointer size) { - return library.brotliEncoderTakeOutput(state, size); - } + Pointer state, Pointer size) => + library.brotliEncoderTakeOutput(state, size); @override BrotliDispatcher get dispatcher => this; diff --git a/lib/src/brotli/ffi/library.dart b/lib/src/brotli/ffi/library.dart index 4af0817..eb587fc 100644 --- a/lib/src/brotli/ffi/library.dart +++ b/lib/src/brotli/ffi/library.dart @@ -48,9 +48,7 @@ class BrotliLibrary String get moduleId => 'brotli'; /// Return the [BrotliLibrary] singleton library instance. - factory BrotliLibrary() { - return _instance; - } + factory BrotliLibrary() => _instance; /// Internal constructor that opens the native shared library and resolves /// all the functions. diff --git a/lib/src/brotli/options.dart b/lib/src/brotli/options.dart index dd74832..d64952d 100644 --- a/lib/src/brotli/options.dart +++ b/lib/src/brotli/options.dart @@ -2,6 +2,8 @@ // 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 '../../brotli.dart'; + /// Exposes Brotli options for input parameters. abstract class BrotliOption { /// Default value for [BrotliCodec.level] and [BrotliEncoder.level]. diff --git a/lib/src/brotli/stubs/codec.dart b/lib/src/brotli/stubs/codec.dart index 010ab3c..084d9ae 100644 --- a/lib/src/brotli/stubs/codec.dart +++ b/lib/src/brotli/stubs/codec.dart @@ -16,7 +16,7 @@ String? brotliGetLibraryPath() => null; /// library path. /// /// This is the stubbed version that be a no-op. -void brotliSetLibraryPath(String? path) => null; +void brotliSetLibraryPath(String? path) {} /// Extension that provides suitable stubs for [BrotliCodec]s in non-IO /// environments. diff --git a/lib/src/brotli/stubs/compress_filter.dart b/lib/src/brotli/stubs/compress_filter.dart index 4e200bf..f152ee0 100644 --- a/lib/src/brotli/stubs/compress_filter.dart +++ b/lib/src/brotli/stubs/compress_filter.dart @@ -4,6 +4,8 @@ import '../../../framework.dart'; +// ignore_for_file: avoid_unused_constructor_parameters + /// Class that provides suitable stubs for [BrotliCompressFilter]s in non-IO /// environments. /// diff --git a/lib/src/brotli/stubs/decompress_filter.dart b/lib/src/brotli/stubs/decompress_filter.dart index 92c868d..5a1a376 100644 --- a/lib/src/brotli/stubs/decompress_filter.dart +++ b/lib/src/brotli/stubs/decompress_filter.dart @@ -4,6 +4,8 @@ import '../../../framework.dart'; +// ignore_for_file: avoid_unused_constructor_parameters + /// Class that provides suitable stubs for [BrotliDecompressFilter]s in non-IO /// environments. /// diff --git a/lib/src/framework/buffers.dart b/lib/src/framework/buffers.dart index ee31a87..0f442d5 100644 --- a/lib/src/framework/buffers.dart +++ b/lib/src/framework/buffers.dart @@ -163,7 +163,7 @@ abstract class CodecBuffer { /// /// The range from [start] to [end] must be a valid range of [bytes]. /// If [start] is omitted, it defaults to zero. - /// If [end] is omitted, it defaults to [bytes.length]. + /// If [end] is omitted, it defaults to the length of [bytes]. /// /// The number of bytes put may be additionally constrained by the /// remaining [unwrittenCount]. @@ -317,7 +317,7 @@ abstract class CodecBuffer { /// Provides a simple buffer holder/builder with a customizable builder function /// [bufferBuilderFunc]. /// -/// The motivation is to help subclasses of [CodecFilter] to customize the +/// The motivation is to help subclasses of `CodecFilter` to customize the /// building of [CodecBuffer] by adjusting either the length or the buffer /// construction call itself. /// diff --git a/lib/src/framework/converters.dart b/lib/src/framework/converters.dart index 8552546..32c53fe 100644 --- a/lib/src/framework/converters.dart +++ b/lib/src/framework/converters.dart @@ -15,7 +15,7 @@ class CodecConverter extends Converter, List> { /// chunked conversion. @override List convert(List bytes) { - var sink = BufferSink(); + final sink = BufferSink(); if (performOneShotConversion(sink, bytes) == false) { startChunkedConversion(sink) ..add(bytes) @@ -29,9 +29,7 @@ class CodecConverter extends Converter, List> { /// /// Return [:false:] if one-shot is not to be (or could not be) performed, /// otherwise answer [:true:] - bool performOneShotConversion(Sink> sink, List bytes) { - return false; - } + bool performOneShotConversion(Sink> sink, List bytes) => false; /// Ensure a conversion to [ByteConversionSink] which provides an interface /// for converters to efficiently transmit byte data. diff --git a/lib/src/framework/dart/filters.dart b/lib/src/framework/dart/filters.dart index 6d61071..fa071cf 100644 --- a/lib/src/framework/dart/filters.dart +++ b/lib/src/framework/dart/filters.dart @@ -16,9 +16,8 @@ abstract class DartCodecFilterBase /// Return a [DartCodecBufferHolder] with the intended [length]. @override CodecBufferHolder newBufferHolder( - int length) { - return DartCodecBufferHolder(length); - } + int length) => + DartCodecBufferHolder(length); /// Init the filter. /// @@ -26,31 +25,27 @@ abstract class DartCodecFilterBase /// the input [bytes]. @override int doInit( - CodecBufferHolder inputBufferHolder, - CodecBufferHolder outputBufferHolder, - List bytes, - int start, - int end) { - return 0; - } + CodecBufferHolder inputBufferHolder, + CodecBufferHolder + outputBufferHolder, + List bytes, + int start, + int end) => + 0; /// Flush the internal-algorithm buffered output data. /// /// The default behavior is to return 0 for the number of bytes flushed to the /// [outputBuffer]. @override - int doFlush(DartCodecBuffer outputBuffer) { - return 0; - } + int doFlush(DartCodecBuffer outputBuffer) => 0; /// Perform algorithm-specific finalization. /// /// The default behavior is to return 0 for the number of bytes written to /// the [outputBuffer]. @override - int doFinalize(DartCodecBuffer outputBuffer) { - return 0; - } + int doFinalize(DartCodecBuffer outputBuffer) => 0; /// Perform tear-down procedures. /// diff --git a/lib/src/framework/filters.dart b/lib/src/framework/filters.dart index b73bba1..200ccff 100644 --- a/lib/src/framework/filters.dart +++ b/lib/src/framework/filters.dart @@ -146,11 +146,10 @@ abstract class CodecFilter> { /// /// There is more to process if data is remaining in either buffer to be read. /// There is more to process if a non-empty [_InputData] exists. - bool hasMoreToProcess() { - return _toProcess.isNotEmpty || - (_inputBuffer.unreadCount > 0) || - (_outputBuffer.unreadCount > 0); - } + bool hasMoreToProcess() => + _toProcess.isNotEmpty || + (_inputBuffer.unreadCount > 0) || + (_outputBuffer.unreadCount > 0); /// Perform a coder/decoder routine where the bytes from the incoming buffer /// are processed by the algorithm and the resulting processed bytes are @@ -172,9 +171,8 @@ abstract class CodecFilter> { /// Any bytes in the input buffer are first processed. /// This is followed by a series of flush calls, each of which /// will add the flushed bytes to [bytesBuilder] if available. - int _flush(final BytesBuilder bytesBuilder) { - return _flushOrFinalizeOperation(bytesBuilder, doFlush); - } + int _flush(final BytesBuilder bytesBuilder) => + _flushOrFinalizeOperation(bytesBuilder, doFlush); /// Finalize the processing which may produce bytes to be added to /// [bytesBuilder]. Return the number of bytes finalized. @@ -258,7 +256,7 @@ abstract class CodecFilter> { /// buffers are created. /// /// Other algorithms, such as encoders, can use this hook to write initial - /// header information to the [outputBufferHolder.buffer]. + /// header information to the [outputBufferHolder] buffer. /// /// The framework needs to be able to detect how much was read from /// [bytes] and the caller should return this value. @@ -280,14 +278,14 @@ abstract class CodecFilter> { /// A request is being made to process bytes from the [inputBuffer] and place /// the results in the [outputBuffer] /// - /// The [inputBuffer.readPtr] is a [CB] buffer to the read position and - /// [inputBuffer.unreadCount] is the maximum number of bytes that can be read + /// The `inputBuffer.readPtr` is a [CB] buffer to the read position and + /// `inputBuffer.unreadCount` is the maximum number of bytes that can be read /// from the buffer. /// /// The resulting bytes can be placed in the [outputBuffer]. Callers will need /// to take care to write only the amount that can be written. - /// The [outputBuffer.writePtr] is a [CB] buffer to the write position and - /// [outputBuffer.unwrittenCount] is the number of bytes that can be written + /// The `outputBuffer.writePtr` is a [CB] buffer to the write position and + /// `outputBuffer.unwrittenCount` is the number of bytes that can be written /// to the buffer. /// /// Callers do not need to adjust read/write positions of the [CodecBuffer]. @@ -303,15 +301,15 @@ abstract class CodecFilter> { /// Many algorithms have internal buffering applied within the native /// shared library in addition to the [CodecBuffer]s in the framework. /// - /// This call should flush up to [outputBuffer.unwrittenCount] into the output - /// buffer starting at [outputBuffer.writePtr]. + /// This call should flush up to `outputBuffer.unwrittenCount` into the output + /// buffer starting at `outputBuffer.writePtr`. /// /// The framework will perform multiple rounds of this call until all data is /// flushed into the destination that the framework has. /// /// Callers should answer 0 if there is no additional data to flush. /// - /// Return the number of bytes flushed (<= [outputBuffer.unwrittenCount]) + /// Return the number of bytes flushed (<= `outputBuffer.unwrittenCount`) int doFlush(CB outputBuffer); /// Subclass Responsibility: Perform algorithm-specific finalization. @@ -325,7 +323,7 @@ abstract class CodecFilter> { /// Callers should answer 0 if there is no additional data to finalize. /// /// Return the number of bytes added for finalization - /// (<= [outputBuffer.unwrittenCount]). + /// (<= `outputBuffer.unwrittenCount`). int doFinalize(CB outputBuffer); /// Subclass Responsibility: Tear-down the filter diff --git a/lib/src/framework/native/buffers.dart b/lib/src/framework/native/buffers.dart index 7cf37e2..786d155 100644 --- a/lib/src/framework/native/buffers.dart +++ b/lib/src/framework/native/buffers.dart @@ -9,8 +9,6 @@ import '../buffers.dart'; /// OS heap. /// /// The backing buffer is referenced by a [Pointer]. -/// There are base, read and write [DartHeapPointer]s required by the -/// superclass which are also instances of [Pointer]. /// /// This buffer is designed to be used by codec algorithms that are implemented /// using Dart's ffi framework.. diff --git a/lib/src/framework/native/filters.dart b/lib/src/framework/native/filters.dart index 8197149..f1cd29b 100644 --- a/lib/src/framework/native/filters.dart +++ b/lib/src/framework/native/filters.dart @@ -15,12 +15,11 @@ abstract class NativeCodecFilterBase inputBufferLength: inputBufferLength, outputBufferLength: outputBufferLength); - /// Return a [DartCodecBufferHolder] with the intended [length]. + /// Return a [CodecBufferHolder] with the intended [length]. @override CodecBufferHolder, NativeCodecBuffer> newBufferHolder( - int length) { - return NativeCodecBufferHolder(length); - } + int length) => + NativeCodecBufferHolder(length); /// Init the filter. /// @@ -28,31 +27,28 @@ abstract class NativeCodecFilterBase /// the input [bytes]. @override int doInit( - CodecBufferHolder, NativeCodecBuffer> inputBufferHolder, - CodecBufferHolder, NativeCodecBuffer> outputBufferHolder, - List bytes, - int start, - int end) { - return 0; - } + CodecBufferHolder, NativeCodecBuffer> + inputBufferHolder, + CodecBufferHolder, NativeCodecBuffer> + outputBufferHolder, + List bytes, + int start, + int end) => + 0; /// Flush the internal-algorithm buffered output data. /// /// The default behavior is to return 0 for the number of bytes flushed to the /// [outputBuffer]. @override - int doFlush(NativeCodecBuffer outputBuffer) { - return 0; - } + int doFlush(NativeCodecBuffer outputBuffer) => 0; /// Perform algorithm-specific finalization. /// /// The default behavior is to return 0 for the number of bytes written to /// the [outputBuffer]. @override - int doFinalize(NativeCodecBuffer outputBuffer) { - return 0; - } + int doFinalize(NativeCodecBuffer outputBuffer) => 0; /// Perform tear-down procedures. /// diff --git a/lib/src/framework/native/library/envvar_strategy.dart b/lib/src/framework/native/library/envvar_strategy.dart index 41887fe..c50e47e 100644 --- a/lib/src/framework/native/library/envvar_strategy.dart +++ b/lib/src/framework/native/library/envvar_strategy.dart @@ -8,7 +8,7 @@ import 'open_library_strategy.dart'; /// via environment variable. /// /// The user may inject an environment variable of the form -/// [moduleId]_LIBRARY_NAME. For example, if the [moduleId] is lz4, then the +/// moduleId_LIBRARY_NAME. For example, if the moduleId is lz4, then the /// name of the env-var is LZ4_LIBRARY_PATH. /// /// The value of the environment variable may contain either the directory diff --git a/lib/src/framework/native/library/package_relative_strategy.dart b/lib/src/framework/native/library/package_relative_strategy.dart index 04e71a4..3858e49 100644 --- a/lib/src/framework/native/library/package_relative_strategy.dart +++ b/lib/src/framework/native/library/package_relative_strategy.dart @@ -1,3 +1,4 @@ +// ignore_for_file: deprecated_member_use import 'dart:cli' as cli; import 'dart:ffi'; import 'dart:isolate' show Isolate; @@ -50,8 +51,9 @@ class OpenViaPackageRelativeStrategy extends OpenLibraryStrategy { const timeoutSeconds = 5; final libraryUri = Uri.parse(packagePath); final packageUriFuture = Isolate.resolvePackageUri(libraryUri); - final packageUri = cli.waitFor(packageUriFuture, - timeout: const Duration(seconds: timeoutSeconds)); + final packageUri = + cli.waitFor(packageUriFuture, + timeout: const Duration(seconds: timeoutSeconds)); return packageUri; } } diff --git a/lib/src/framework/native/library/stubs/package_relative_strategy.dart b/lib/src/framework/native/library/stubs/package_relative_strategy.dart index d17b9ff..4be8e2b 100644 --- a/lib/src/framework/native/library/stubs/package_relative_strategy.dart +++ b/lib/src/framework/native/library/stubs/package_relative_strategy.dart @@ -14,7 +14,5 @@ class OpenViaPackageRelativeStrategy extends OpenLibraryStrategy { /// Return [:null:]. @override - DynamicLibrary? openFor(OpenLibrary openLibrary) { - return null; - } + DynamicLibrary? openFor(OpenLibrary openLibrary) => null; } diff --git a/lib/src/framework/sinks.dart b/lib/src/framework/sinks.dart index 9e0c4b5..a984ef9 100644 --- a/lib/src/framework/sinks.dart +++ b/lib/src/framework/sinks.dart @@ -25,18 +25,18 @@ class CodecSink extends ByteConversionSink { CodecSink(this._sink, this._filter); @override - void add(List data) { - addSlice(data, 0, data.length, false); + void add(List chunk) { + addSlice(chunk, 0, chunk.length, false); } @override - void addSlice(List data, int start, int end, bool isLast) { + void addSlice(List chunk, int start, int end, bool isLast) { if (_closed) return; - RangeError.checkValidRange(start, end, data.length); + RangeError.checkValidRange(start, end, chunk.length); try { _empty = false; - var bufferAndStart = - _PositionableBuffer.serializableByteData(data, start, end); + final bufferAndStart = + _PositionableBuffer.serializableByteData(chunk, start, end); _filter.process(bufferAndStart.buffer, bufferAndStart.start, end - (start - bufferAndStart.start)); while (true) { @@ -87,8 +87,8 @@ class _PositionableBuffer { if (buffer is Uint8List || buffer is Int8List) { return _PositionableBuffer(buffer, start); } - var length = end - start; - var newBuffer = Uint8List(length); + final length = end - start; + final newBuffer = Uint8List(length); newBuffer.setRange(0, length, buffer, start); return _PositionableBuffer(newBuffer, 0); } @@ -110,7 +110,7 @@ class BufferSink extends ByteConversionSink { @override void addSlice(List chunk, int start, int end, bool isLast) { if (chunk is Uint8List) { - var list = chunk; + final list = chunk; builder.add(Uint8List.view(list.buffer, start, end - start)); } else { builder.add(chunk.sublist(start, end)); diff --git a/lib/src/lz4/codec.dart b/lib/src/lz4/codec.dart index 82bdeca..8cc0e0f 100644 --- a/lib/src/lz4/codec.dart +++ b/lib/src/lz4/codec.dart @@ -70,7 +70,7 @@ class Lz4Codec extends Codec, List> { final int outputBufferLength; /// Return the base binding version this binding code was developed for. - Lz4Version get bindingVersion => Lz4Version(10902); + Lz4Version get bindingVersion => const Lz4Version(10902); /// Return the actual library version of the shared library. Lz4Version get libraryVersion => Lz4Version(libraryVersionNumber); @@ -106,11 +106,11 @@ class Lz4Codec extends Codec, List> { inputBufferLength = CodecBufferHolder.autoLength, outputBufferLength = CodecBufferHolder.autoLength; - /// Return the [Lz4Encoder] configured implementation. + /// Return the lz4 encoder configured implementation. @override Converter, List> get encoder => encoderImpl; - /// Return the [Lz4Decoder] configured implementation. + /// Return the lz4 decoder configured implementation. @override Converter, List> get decoder => decoderImpl; } diff --git a/lib/src/lz4/decoder.dart b/lib/src/lz4/decoder.dart index 9687274..fc6f16f 100644 --- a/lib/src/lz4/decoder.dart +++ b/lib/src/lz4/decoder.dart @@ -5,9 +5,6 @@ import 'dart:convert'; import '../../framework.dart'; -import '../framework/converters.dart'; -import '../framework/sinks.dart'; -import 'codec.dart'; import 'stubs/decompress_filter.dart' if (dart.library.io) 'ffi/decompress_filter.dart'; @@ -17,7 +14,7 @@ const lz4DecoderInputBufferLength = 256 * 1024; /// Default output buffer length. const lz4DecoderOutputBufferLength = lz4DecoderInputBufferLength * 2; -/// The [Lz4Decoder] decoder is used by [Lz4Codec] to decompress lz4 data. +/// The [Lz4Decoder] decoder is used to decompress lz4 data. class Lz4Decoder extends CodecConverter { /// Length in bytes of the buffer used for input data. final int inputBufferLength; @@ -56,6 +53,5 @@ class _Lz4DecoderSink extends CodecSink { /// There is a conditional import that determines the implementation of /// [Lz4DecompressFilter] based on the environment. CodecFilter _makeLz4DecompressFilter( - int inputBufferLength, int outputBufferLength) { - return Lz4DecompressFilter(inputBufferLength, outputBufferLength); -} + int inputBufferLength, int outputBufferLength) => + Lz4DecompressFilter(inputBufferLength, outputBufferLength); diff --git a/lib/src/lz4/encoder.dart b/lib/src/lz4/encoder.dart index 7914f4b..0893043 100644 --- a/lib/src/lz4/encoder.dart +++ b/lib/src/lz4/encoder.dart @@ -7,7 +7,6 @@ import 'dart:convert'; import '../framework/converters.dart'; import '../framework/filters.dart'; import '../framework/sinks.dart'; -import 'codec.dart'; import 'options.dart'; import 'stubs/compress_filter.dart' if (dart.library.io) 'ffi/compress_filter.dart'; @@ -19,7 +18,7 @@ const lz4EncoderInputBufferLength = 256 * 1024; /// Default output buffer length. const lz4EncoderOutputBufferLength = lz4EncoderInputBufferLength; -/// The [Lz4Encoder] encoder is used by [Lz4Codec] to lz4 compress data. +/// The [Lz4Encoder] encoder is used to lz4 compress data. class Lz4Encoder extends CodecConverter { /// The compression-[level] can be set in the range of `0..16`, with /// 0 (fast mode) being the default compression level. @@ -135,23 +134,22 @@ class _Lz4EncoderSink extends CodecSink { /// There is a conditional import that determines the implementation of /// [Lz4CompressFilter] based on the environment. CodecFilter _makeLz4CompressFilter( - int level, - bool fastAcceleration, - bool contentChecksum, - bool blockChecksum, - bool blockLinked, - int blockSize, - bool optimizeForCompression, - int inputBufferLength, - int outputBufferLength) { - return Lz4CompressFilter( - level: level, - fastAcceleration: fastAcceleration, - contentChecksum: contentChecksum, - blockChecksum: blockChecksum, - blockLinked: blockLinked, - blockSize: blockSize, - optimizeForCompression: optimizeForCompression, - inputBufferLength: inputBufferLength, - outputBufferLength: outputBufferLength); -} + int level, + bool fastAcceleration, + bool contentChecksum, + bool blockChecksum, + bool blockLinked, + int blockSize, + bool optimizeForCompression, + int inputBufferLength, + int outputBufferLength) => + Lz4CompressFilter( + level: level, + fastAcceleration: fastAcceleration, + contentChecksum: contentChecksum, + blockChecksum: blockChecksum, + blockLinked: blockLinked, + blockSize: blockSize, + optimizeForCompression: optimizeForCompression, + inputBufferLength: inputBufferLength, + outputBufferLength: outputBufferLength); diff --git a/lib/src/lz4/ffi/compress_filter.dart b/lib/src/lz4/ffi/compress_filter.dart index f6c1007..1a4c6a3 100644 --- a/lib/src/lz4/ffi/compress_filter.dart +++ b/lib/src/lz4/ffi/compress_filter.dart @@ -58,10 +58,10 @@ class Lz4CompressFilter extends NativeCodecFilterBase { /// Init the filter. /// /// 1. Provide appropriate buffer lengths to codec builders - /// [inputBufferHolder.length] decoding buffer length and - /// [outputBufferHolder.length] encoding buffer length. - /// Ensure that the [outputBufferHolder.length] is at least as large as the - /// maximum size of an lz4 block given the [inputBufferHolder.length]. + /// `inputBufferHolder.length` decoding buffer length and + /// `outputBufferHolder.length` encoding buffer length. + /// Ensure that the `outputBufferHolder.length` is at least as large as the + /// maximum size of an lz4 block given the `inputBufferHolder.length`. /// /// 2. Allocate and setup the native lz4 context. /// @@ -91,9 +91,9 @@ class Lz4CompressFilter extends NativeCodecFilterBase { return 0; } - /// Perform an lz4 encoding of [inputBuffer.unreadCount] bytes in + /// Perform an lz4 encoding of `inputBuffer.unreadCount` bytes in /// and put the resulting encoded bytes into [outputBuffer] of length - /// [outputBuffer.unwrittenCount]. + /// `outputBuffer.unwrittenCount`. /// /// Return an [CodecResult] which describes the amount read/write. @override @@ -113,17 +113,15 @@ class Lz4CompressFilter extends NativeCodecFilterBase { /// /// Return the number of bytes flushed. @override - int doFlush(NativeCodecBuffer outputBuffer) { - return _dispatcher.callLz4FFlush( - _context, outputBuffer.writePtr, outputBuffer.unwrittenCount, _options); - } + int doFlush(NativeCodecBuffer outputBuffer) => _dispatcher.callLz4FFlush( + _context, outputBuffer.writePtr, outputBuffer.unwrittenCount, _options); /// Lz4 finalize implementation. /// /// Only 1 round of finalization is required, put filter state into /// the finalized state. /// - /// A [FormatException] is thrown if [outputBufferLength] is not of sufficient + /// A [FormatException] is thrown if [outputBuffer] is not of sufficient /// length. /// A [FormatException] is thrown if writing out the lz4 trailer fails. @override @@ -132,7 +130,7 @@ class Lz4CompressFilter extends NativeCodecFilterBase { if (writeLength < 4 || (_preferences.ref.frameInfoContentChecksumFlag != 0 && writeLength < 8)) { - FormatException( + const FormatException( 'buffer capacity is too small to properly finish the lz4 frame'); } final numBytes = _dispatcher.callLz4FCompressEnd( @@ -176,9 +174,8 @@ class Lz4CompressFilter extends NativeCodecFilterBase { /// Return the maximum length of an lz4 block, given its uncompressed /// [uncompressedLength] and header size. - int _lz4CompressBound(int uncompressedLength) { - return _dispatcher.callLz4FCompressBound(uncompressedLength, _preferences); - } + int _lz4CompressBound(int uncompressedLength) => + _dispatcher.callLz4FCompressBound(uncompressedLength, _preferences); /// Free the native context. /// diff --git a/lib/src/lz4/ffi/decompress_filter.dart b/lib/src/lz4/ffi/decompress_filter.dart index bc12dfb..bed672e 100644 --- a/lib/src/lz4/ffi/decompress_filter.dart +++ b/lib/src/lz4/ffi/decompress_filter.dart @@ -41,10 +41,10 @@ class Lz4DecompressFilter extends NativeCodecFilterBase { /// Init the filter. /// /// 1. Provide appropriate buffer lengths to codec builders - /// [inputBufferHolder.length] decoding buffer length and - /// [outputBufferHolder.length] encoding buffer length. - /// Ensure that the [outputBufferHolder.length] is at least as large as the - /// maximum size of an lz4 block given the [inputBufferHolder.length]. + /// [inputBufferHolder] decoding buffer length and + /// [outputBufferHolder] encoding buffer length. + /// Ensure that the [outputBufferHolder] is at least as large as the + /// maximum size of an lz4 block given the [inputBufferHolder]. /// /// 2. Allocate and setup the native lz4 context. /// diff --git a/lib/src/lz4/ffi/dispatcher.dart b/lib/src/lz4/ffi/dispatcher.dart index 7e2f91e..9e8f49b 100644 --- a/lib/src/lz4/ffi/dispatcher.dart +++ b/lib/src/lz4/ffi/dispatcher.dart @@ -57,17 +57,12 @@ class Lz4Dispatcher with Lz4DispatchErrorCheckerMixin { } } - int callLz4VersionNumber() { - return library.lz4VersionNumber(); - } + int callLz4VersionNumber() => library.lz4VersionNumber(); - int callLz4FIsError(int code) { - return library.lz4FIsError(code); - } + int callLz4FIsError(int code) => library.lz4FIsError(code); - Pointer callLz4FGetErrorName(int code) { - return library.lz4FGetErrorName(code); - } + Pointer callLz4FGetErrorName(int code) => + library.lz4FGetErrorName(code); Pointer callLz4FCreateCompressionContext( {int version = Lz4Constants.LZ4F_VERSION}) { @@ -78,57 +73,48 @@ class Lz4Dispatcher with Lz4DispatchErrorCheckerMixin { return newCtx; } - int callLz4FFreeCompressionContext(Pointer context) { - return checkError(library.lz4FFreeCompressionContext(context)); - } + int callLz4FFreeCompressionContext(Pointer context) => + checkError(library.lz4FFreeCompressionContext(context)); int callLz4FCompressBegin(Pointer context, Pointer destBuffer, - int destSize, Pointer preferences) { - return checkError( - library.lz4FCompressBegin(context, destBuffer, destSize, preferences)); - } + int destSize, Pointer preferences) => + checkError(library.lz4FCompressBegin( + context, destBuffer, destSize, preferences)); - int callLz4FCompressBound(int srcSize, Pointer preferences) { - return checkError(library.lz4FCompressBound(srcSize, preferences)); - } + int callLz4FCompressBound(int srcSize, Pointer preferences) => + checkError(library.lz4FCompressBound(srcSize, preferences)); int callLz4FCompressFrameBound( - int srcSize, Pointer preferences) { - return checkError(library.lz4FCompressFrameBound(srcSize, preferences)); - } + int srcSize, Pointer preferences) => + checkError(library.lz4FCompressFrameBound(srcSize, preferences)); int callLz4CompressFrame( - Pointer dstBuffer, - int dstCapacity, - Pointer srcBuffer, - int srcSize, - Pointer preferences) { - return checkError(library.lz4FCompressFrame( - dstBuffer, dstCapacity, srcBuffer, srcSize, preferences)); - } + Pointer dstBuffer, + int dstCapacity, + Pointer srcBuffer, + int srcSize, + Pointer preferences) => + checkError(library.lz4FCompressFrame( + dstBuffer, dstCapacity, srcBuffer, srcSize, preferences)); int callLz4FCompressUpdate( - Pointer context, - Pointer destBuffer, - int destSize, - Pointer srcBuffer, - int srcSize, - Pointer options) { - return checkError(library.lz4FCompressUpdate( - context, destBuffer, destSize, srcBuffer, srcSize, options)); - } + Pointer context, + Pointer destBuffer, + int destSize, + Pointer srcBuffer, + int srcSize, + Pointer options) => + checkError(library.lz4FCompressUpdate( + context, destBuffer, destSize, srcBuffer, srcSize, options)); int callLz4FFlush(Pointer context, Pointer destBuffer, - int destSize, Pointer options) { - return checkError( - library.lz4FFlush(context, destBuffer, destSize, options)); - } + int destSize, Pointer options) => + checkError(library.lz4FFlush(context, destBuffer, destSize, options)); int callLz4FCompressEnd(Pointer context, Pointer destBuffer, - int destSize, Pointer options) { - return checkError( - library.lz4FCompressEnd(context, destBuffer, destSize, options)); - } + int destSize, Pointer options) => + checkError( + library.lz4FCompressEnd(context, destBuffer, destSize, options)); Pointer callLz4FCreateDecompressionContext( {int version = Lz4Constants.LZ4F_VERSION}) { @@ -139,9 +125,8 @@ class Lz4Dispatcher with Lz4DispatchErrorCheckerMixin { return newCtx; } - int callLz4FFreeDecompressionContext(Pointer context) { - return checkError(library.lz4FFreeDecompressionContext(context)); - } + int callLz4FFreeDecompressionContext(Pointer context) => + checkError(library.lz4FFreeDecompressionContext(context)); List callLz4FGetFrameInfo( Pointer context, Pointer srcBuffer, int compressedSize) { @@ -155,9 +140,8 @@ class Lz4Dispatcher with Lz4DispatchErrorCheckerMixin { return [result, frameInfo, read]; } - void callLz4FResetDecompressionContext(Pointer context) { - return library.lz4FResetDecompressionContext(context); - } + void callLz4FResetDecompressionContext(Pointer context) => + library.lz4FResetDecompressionContext(context); List callLz4FDecompress( Pointer context, diff --git a/lib/src/lz4/ffi/library.dart b/lib/src/lz4/ffi/library.dart index d55b6d2..c304bcb 100644 --- a/lib/src/lz4/ffi/library.dart +++ b/lib/src/lz4/ffi/library.dart @@ -46,9 +46,7 @@ class Lz4Library with OpenLibrary, Lz4Constants, Lz4Functions, Lz4Types { String get moduleId => 'lz4'; /// Return the [Lz4Library] singleton library instance. - factory Lz4Library() { - return _instance; - } + factory Lz4Library() => _instance; /// Internal constructor that opens the native shared library and resolves /// all the functions. diff --git a/lib/src/lz4/options.dart b/lib/src/lz4/options.dart index 0677d31..3de311b 100644 --- a/lib/src/lz4/options.dart +++ b/lib/src/lz4/options.dart @@ -2,6 +2,7 @@ // 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 '../../lz4.dart'; import 'ffi/constants.dart'; /// Exposes Lz4 options for input parameters. diff --git a/lib/src/lz4/stubs/codec.dart b/lib/src/lz4/stubs/codec.dart index 3ad1fb3..96a22e0 100644 --- a/lib/src/lz4/stubs/codec.dart +++ b/lib/src/lz4/stubs/codec.dart @@ -16,7 +16,7 @@ String lz4GetLibraryPath() => ''; /// library path. /// /// This is the stubbed version that be a no-op. -void lz4SetLibraryPath(String? path) => null; +void lz4SetLibraryPath(String? path) {} /// Extension that provides suitable stubs for [Lz4Codec]s in non-IO /// environments. diff --git a/lib/src/lz4/stubs/compress_filter.dart b/lib/src/lz4/stubs/compress_filter.dart index a4919df..0a561a6 100644 --- a/lib/src/lz4/stubs/compress_filter.dart +++ b/lib/src/lz4/stubs/compress_filter.dart @@ -4,6 +4,8 @@ import '../../../framework.dart'; +// ignore_for_file: avoid_unused_constructor_parameters + /// Class that provides suitable stubs for [Lz4CompressFilter]s in non-IO /// environments. /// diff --git a/lib/src/lz4/stubs/decompress_filter.dart b/lib/src/lz4/stubs/decompress_filter.dart index 808106d..b8e9b16 100644 --- a/lib/src/lz4/stubs/decompress_filter.dart +++ b/lib/src/lz4/stubs/decompress_filter.dart @@ -4,6 +4,8 @@ import '../../../framework.dart'; +// ignore_for_file: avoid_unused_constructor_parameters + /// Class that provides suitable stubs for [Lz4DecompressFilter]s in non-IO /// environments. /// diff --git a/lib/src/zstd/codec.dart b/lib/src/zstd/codec.dart index 6debeaf..1dbe65b 100644 --- a/lib/src/zstd/codec.dart +++ b/lib/src/zstd/codec.dart @@ -40,7 +40,7 @@ class ZstdCodec extends Codec, List> { final int outputBufferLength; /// Return the base binding version this binding code was developed for. - ZstdVersion get bindingVersion => ZstdVersion(10500); + ZstdVersion get bindingVersion => const ZstdVersion(10500); /// Return the actual library version of the shared library. ZstdVersion get libraryVersion => ZstdVersion(libraryVersionNumber); @@ -63,11 +63,11 @@ class ZstdCodec extends Codec, List> { inputBufferLength = CodecBufferHolder.autoLength, outputBufferLength = CodecBufferHolder.autoLength; - /// Return the [ZstdEncoder] configured implementation. + /// Return the zstd encoder configured implementation. @override Converter, List> get encoder => encoderImpl; - /// Return the [ZstdDecoder] configured implementation. + /// Return the zstd decoder configured implementation. @override Converter, List> get decoder => decoderImpl; } diff --git a/lib/src/zstd/decoder.dart b/lib/src/zstd/decoder.dart index 545817a..1429b37 100644 --- a/lib/src/zstd/decoder.dart +++ b/lib/src/zstd/decoder.dart @@ -5,9 +5,6 @@ import 'dart:convert'; import '../../framework.dart'; -import '../framework/buffers.dart'; -import '../framework/converters.dart'; -import '../framework/sinks.dart'; import 'ffi/constants.dart'; import 'stubs/decompress_filter.dart' if (dart.library.io) 'ffi/decompress_filter.dart'; @@ -18,7 +15,7 @@ const zstdDecoderInputBufferLength = ZstdConstants.ZSTD_BLOCKSIZE_MAX + 3; /// Default output buffer length. const zstdDecoderOutputBufferLength = CodecBufferHolder.autoLength; -/// The [ZstdDecoder] decoder is used by [ZstdCodec] to decompress zstd data. +/// The [ZstdDecoder] decoder is used to decompress zstd data. class ZstdDecoder extends CodecConverter { /// Length in bytes of the buffer used for input data. final int inputBufferLength; @@ -57,6 +54,5 @@ class _ZstdDecoderSink extends CodecSink { /// There is a conditional import that determines the implementation of /// [ZstdDecompressFilter] based on the environment. CodecFilter _makeZstdCompressFilter( - int inputBufferLength, int outputBufferLength) { - return ZstdDecompressFilter(inputBufferLength, outputBufferLength); -} + int inputBufferLength, int outputBufferLength) => + ZstdDecompressFilter(inputBufferLength, outputBufferLength); diff --git a/lib/src/zstd/encoder.dart b/lib/src/zstd/encoder.dart index 4dd8570..9dcb118 100644 --- a/lib/src/zstd/encoder.dart +++ b/lib/src/zstd/encoder.dart @@ -20,7 +20,7 @@ const zstdEncoderInputBufferLength = ZstdConstants.ZSTD_BLOCKSIZE_MAX; /// Default output buffer length. const zstdEncoderOutputBufferLength = CodecBufferHolder.autoLength; -/// The [ZstdEncoder] encoder is used by [ZstdCodec] to zstd compress data. +/// The [ZstdEncoder] encoder is used to zstd compress data. class ZstdEncoder extends CodecConverter { /// The compression-[level] can be set in the range of /// `-[ZstdConstants.ZSTD_TARGETLENGTH_MAX]..22`, @@ -74,9 +74,8 @@ class _ZstdEncoderSink extends CodecSink { /// There is a conditional import that determines the implementation of /// [ZstdCompressFilter] based on the environment. CodecFilter _makeZstdCompressFilter( - int level, int inputBufferLength, int outputBufferLength) { - return ZstdCompressFilter( - level: level, - inputBufferLength: inputBufferLength, - outputBufferLength: outputBufferLength); -} + int level, int inputBufferLength, int outputBufferLength) => + ZstdCompressFilter( + level: level, + inputBufferLength: inputBufferLength, + outputBufferLength: outputBufferLength); diff --git a/lib/src/zstd/ffi/compress_filter.dart b/lib/src/zstd/ffi/compress_filter.dart index b6d4ab6..046a28c 100644 --- a/lib/src/zstd/ffi/compress_filter.dart +++ b/lib/src/zstd/ffi/compress_filter.dart @@ -37,8 +37,8 @@ class ZstdCompressFilter extends NativeCodecFilterBase { /// Init the filter. /// /// Provide appropriate buffer lengths to codec builders - /// [inputBufferHolder.length] decoding buffer length and - /// [outputBufferHolder.length] encoding buffer length. + /// [inputBufferHolder] decoding buffer length and + /// [outputBufferHolder] encoding buffer length. @override int doInit( CodecBufferHolder, NativeCodecBuffer> inputBufferHolder, @@ -65,14 +65,13 @@ class ZstdCompressFilter extends NativeCodecFilterBase { /// /// Return the number of bytes flushed. @override - int doFlush(NativeCodecBuffer outputBuffer) { - return _dispatcher.callZstdFlushStream( - _cStream, outputBuffer.writePtr, outputBuffer.unwrittenCount); - } + int doFlush(NativeCodecBuffer outputBuffer) => + _dispatcher.callZstdFlushStream( + _cStream, outputBuffer.writePtr, outputBuffer.unwrittenCount); - /// Perform an zstd encoding of [inputBuffer.unreadCount] bytes in + /// Perform an zstd encoding of `inputBuffer.unreadCount` bytes in /// and put the resulting encoded bytes into [outputBuffer] of length - /// [outputBuffer.unwrittenCount]. + /// `outputBuffer.unwrittenCount`. /// /// Return an [CodecResult] which describes the amount read/write. @override diff --git a/lib/src/zstd/ffi/decompress_filter.dart b/lib/src/zstd/ffi/decompress_filter.dart index 184d5d9..0e288c0 100644 --- a/lib/src/zstd/ffi/decompress_filter.dart +++ b/lib/src/zstd/ffi/decompress_filter.dart @@ -29,8 +29,8 @@ class ZstdDecompressFilter extends NativeCodecFilterBase { /// Init the filter /// /// Provide appropriate buffer lengths to codec builders - /// [inputBufferHolder.length] decoding buffer length and - /// [outputBufferHolder.length] encoding buffer length. + /// [inputBufferHolder] decoding buffer length and + /// [outputBufferHolder] encoding buffer length. @override int doInit( CodecBufferHolder, NativeCodecBuffer> inputBufferHolder, diff --git a/lib/src/zstd/ffi/library.dart b/lib/src/zstd/ffi/library.dart index 229b1ca..abcb518 100644 --- a/lib/src/zstd/ffi/library.dart +++ b/lib/src/zstd/ffi/library.dart @@ -46,9 +46,7 @@ class ZstdLibrary with OpenLibrary, ZstdConstants, ZstdFunctions, ZstdTypes { String get moduleId => 'zstd'; /// Return the [ZstdLibrary] singleton library instance. - factory ZstdLibrary() { - return _instance; - } + factory ZstdLibrary() => _instance; /// Internal constructor that opens the native shared library and resolves /// all the functions. diff --git a/lib/src/zstd/options.dart b/lib/src/zstd/options.dart index af52bc1..79d5783 100644 --- a/lib/src/zstd/options.dart +++ b/lib/src/zstd/options.dart @@ -2,6 +2,7 @@ // 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 '../../zstd.dart'; import 'ffi/constants.dart'; /// Exposes Zstd options for input parameters. diff --git a/lib/src/zstd/stubs/codec.dart b/lib/src/zstd/stubs/codec.dart index 5c170e1..4de803b 100644 --- a/lib/src/zstd/stubs/codec.dart +++ b/lib/src/zstd/stubs/codec.dart @@ -16,7 +16,7 @@ String? zstdGetLibraryPath() => null; /// library path. /// /// This is the stubbed version that be a no-op. -void zstdSetLibraryPath(String? path) => null; +void zstdSetLibraryPath(String? path) {} /// Extension that provides suitable stubs for [ZstdCodec]s in non-IO /// environments. diff --git a/lib/src/zstd/stubs/compress_filter.dart b/lib/src/zstd/stubs/compress_filter.dart index f5d0527..0681957 100644 --- a/lib/src/zstd/stubs/compress_filter.dart +++ b/lib/src/zstd/stubs/compress_filter.dart @@ -4,6 +4,8 @@ import '../../../framework.dart'; +// ignore_for_file: avoid_unused_constructor_parameters + /// Class that provides suitable stubs for [ZstdCompressFilter]s in non-IO /// environments. /// diff --git a/lib/src/zstd/stubs/decompress_filter.dart b/lib/src/zstd/stubs/decompress_filter.dart index 4098f32..034485b 100644 --- a/lib/src/zstd/stubs/decompress_filter.dart +++ b/lib/src/zstd/stubs/decompress_filter.dart @@ -4,6 +4,8 @@ import '../../../framework.dart'; +// ignore_for_file: avoid_unused_constructor_parameters + /// Class that provides suitable stubs for [ZstdDecompressFilter]s in non-IO /// environments. /// diff --git a/pubspec.yaml b/pubspec.yaml index 12743d5..f5bd092 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: es_compression description: Compression framework providing FFI implementations for Brotli, Lz4, Zstd (Zstandard) with ready-to-use prebuilt binaries for Win/Linux/Mac. -version: 2.0.3 +version: 2.0.4 homepage: https://www.instantiations.com issue_tracker: https://github.com/instantiations/es_compression/issues repository: https://github.com/instantiations/es_compression @@ -14,9 +14,11 @@ executables: dependencies: args: ^2.0.0 ffi: ^1.0.0 + stack_trace: ^1.10.0 + stream_channel: ^2.1.0 dev_dependencies: benchmark_harness: ^2.0.0 collection: ^1.15.0 - pedantic: ^1.10.0 + lints: ^1.0.1 test: ^1.16.0 diff --git a/test/brotli_test.dart b/test/brotli_test.dart index 480ce02..1ff72c1 100644 --- a/test/brotli_test.dart +++ b/test/brotli_test.dart @@ -10,8 +10,8 @@ import 'package:test/test.dart'; void main() { test('Test Brotli Version Number', () { - final codec = brotli; - final bindingVersion = '1.0.9'; + const codec = brotli; + const bindingVersion = '1.0.9'; expect(codec.bindingVersion.toString(), bindingVersion); expect(codec.encoderVersion.toString(), bindingVersion); expect(codec.decoderVersion.toString(), bindingVersion); @@ -22,7 +22,7 @@ void main() { }); test('Test Empty Brotli Encode/Decode', () { - final data = ''; + const data = ''; final header = [107, 0, 3]; final dataBytes = utf8.encode(data); final codec = BrotliCodec(); @@ -33,7 +33,7 @@ void main() { }); test('Test Simple Brotli Encode/Decode', () { - final data = 'MyDart'; + const data = 'MyDart'; final expected = [139, 2, 128, 77, 121, 68, 97, 114, 116, 3]; final dataBytes = utf8.encode(data); final codec = BrotliCodec(); diff --git a/test/lz4_test.dart b/test/lz4_test.dart index b671eae..8f13551 100644 --- a/test/lz4_test.dart +++ b/test/lz4_test.dart @@ -10,9 +10,9 @@ import 'package:test/test.dart'; void main() { test('Test Lz4 Version Number', () { - final codec = lz4; - final bindingVersion = '1.9.2'; - final libraryVersion = '1.9.3'; + const codec = lz4; + const bindingVersion = '1.9.2'; + const libraryVersion = '1.9.3'; expect(codec.bindingVersion.toString(), bindingVersion); expect(codec.libraryVersion.toString(), libraryVersion); }); @@ -22,7 +22,7 @@ void main() { }); test('Test Empty Lz4 Encode/Decode', () { - final data = ''; + const data = ''; final header = [4, 34, 77, 24, 68, 64, 94, 0, 0, 0, 0, 5, 93, 204, 2]; final dataBytes = utf8.encode(data); final codec = Lz4Codec(contentChecksum: true); @@ -33,7 +33,7 @@ void main() { }); test('Test Simple Lz4 Encode/Decode', () { - final data = 'MyDart'; + const data = 'MyDart'; final expected = [ 4, 34, diff --git a/test/zstd_test.dart b/test/zstd_test.dart index 78979e1..f69f72b 100644 --- a/test/zstd_test.dart +++ b/test/zstd_test.dart @@ -10,8 +10,8 @@ import 'package:test/test.dart'; void main() { test('Test Zstd Version Number', () { - final codec = zstd; - final bindingVersion = '1.5.0'; + const codec = zstd; + const bindingVersion = '1.5.0'; expect(codec.bindingVersion.toString(), bindingVersion); expect(codec.libraryVersion.toString(), bindingVersion); }); @@ -21,7 +21,7 @@ void main() { }); test('Test Empty Zstd Encode/Decode', () { - final data = ''; + const data = ''; final header = [40, 181, 47, 253, 0, 88, 1, 0, 0]; final dataBytes = utf8.encode(data); final codec = ZstdCodec(); @@ -32,7 +32,7 @@ void main() { }); test('Test Simple Zstd Encode/Decode', () { - final data = 'MyDart'; + const data = 'MyDart'; final expected = [ 40, 181, diff --git a/tool/blob_builder/CMakeLists.txt b/tool/blob_builder/CMakeLists.txt index 88826ad..7f42d9f 100644 --- a/tool/blob_builder/CMakeLists.txt +++ b/tool/blob_builder/CMakeLists.txt @@ -151,10 +151,10 @@ set(LZ4_VERSION_MOD 3) #-- The period-delimited 3 position format (1.0.0) set(LZ4_VERSION "${LZ4_VERSION_MAJOR}.${LZ4_VERSION_MINOR}.${LZ4_VERSION_MOD}") -#-- ZSTD Version: 1.4.9 +#-- ZSTD Version: 1.5.1 set(ZSTD_VERSION_MAJOR 1) set(ZSTD_VERSION_MINOR 5) -set(ZSTD_VERSION_MOD 0) +set(ZSTD_VERSION_MOD 1) #-- The period-delimited 3 position format (1.0.0) set(ZSTD_VERSION "${ZSTD_VERSION_MAJOR}.${ZSTD_VERSION_MINOR}.${ZSTD_VERSION_MOD}")