diff --git a/CHANGELOG.md b/CHANGELOG.md index 40303c8..29e297a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.9.1 + +- **(Breaking Change only for Codec Implementors)** Removed class generic type from `CodecFilter` class. +- Created extendable base class for FFI-based codec filters: [NativeCodecFilterBase](lib/src/framework/native/filters.dart). +- Created extendable base class for non-FFI codec filters: [DartCodecFilterBase](lib/src/framework/dart/filters.dart). +- Refactored existing codec filters to subclass `NativeCodecFilterBase` and `DartCodecFilterBase`. +- Fixed some minor issues with the [README](README.md). + ## 0.9.0 - Initial development release, created by Seth Berman [Instantiations, Inc](https://www.instantiations.com). diff --git a/DESIGN.md b/DESIGN.md index 8800885..057c1dd 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -154,4 +154,8 @@ A [simple example](example/rle_example.dart) was created so implementors could s #### Filters The framework offers a `CodecFilter` that handles most of the external concerns of codec implementations. This class is designed to be subclassed, and subclass implementors will override callback hooks for codec initialization -, processing, flushing, finalizing and closing. All provided codecs build off of the `CodecFilter`. +, processing, flushing, finalizing and closing. + +To simplify things even more, we provide two `CodecFilter` subclasses for implementors to extend: +- [DartCodecFilter](lib/src/framework/dart/filters.dart) for non-ffi codec implementations +- [NativeCodecFilter](lib/src/framework/native/filters.dart) for ffi codec implementations diff --git a/example/rle_example.dart b/example/rle_example.dart index 5e35a89..a0d2731 100644 --- a/example/rle_example.dart +++ b/example/rle_example.dart @@ -7,6 +7,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:es_compression/framework.dart'; +import 'package:es_compression/src/framework/dart/filters.dart'; import 'utils/example_utils.dart'; @@ -84,26 +85,9 @@ class RunLengthEncoder extends CodecConverter { } /// Filter that encodes the incoming bytes using a Dart in-memory buffer. -class RunLengthEncoderFilter - extends CodecFilter { +class RunLengthEncoderFilter extends DartCodecFilterBase { int runLength = 1; - @override - CodecBufferHolder newBufferHolder( - int length) { - return DartCodecBufferHolder(length); - } - - @override - int doInit( - CodecBufferHolder inputBufferHolder, - CodecBufferHolder outputBufferHolder, - List bytes, - int start, - int end) { - return 0; - } - @override CodecResult doProcessing( DartCodecBuffer inputBuffer, DartCodecBuffer outputBuffer) { @@ -126,21 +110,6 @@ class RunLengthEncoderFilter final written = outputBuffer.writeCount - writePos; return CodecResult(read, written, adjustBufferCounts: false); } - - @override - int doFlush(DartCodecBuffer outputBuffer) { - return 0; - } - - @override - int doFinalize(DartCodecBuffer outputBuffer) { - return 0; - } - - @override - void doClose() { - // No action - } } /// Custom decoder that provides a [CodecSink] with the algorithm @@ -156,27 +125,10 @@ class RunLengthDecoder extends CodecConverter { enum RleState { expecting_length, expecting_data } /// Filter that decodes the incoming bytes using a Dart in-memory buffer. -class RunLengthDecoderFilter - extends CodecFilter { +class RunLengthDecoderFilter extends DartCodecFilterBase { RleState _state = RleState.expecting_length; int runLength = 1; - @override - CodecBufferHolder newBufferHolder( - int length) { - return DartCodecBufferHolder(length); - } - - @override - int doInit( - CodecBufferHolder inputBufferHolder, - CodecBufferHolder outputBufferHolder, - List bytes, - int start, - int end) { - return 0; - } - @override CodecResult doProcessing( DartCodecBuffer inputBuffer, DartCodecBuffer outputBuffer) { @@ -202,19 +154,4 @@ class RunLengthDecoderFilter final written = outputBuffer.writeCount - writePos; return CodecResult(read, written, adjustBufferCounts: false); } - - @override - int doFlush(DartCodecBuffer outputBuffer) { - return 0; - } - - @override - int doFinalize(DartCodecBuffer outputBuffer) { - return 0; - } - - @override - void doClose() { - // No action - } } diff --git a/lib/framework.dart b/lib/framework.dart index 5b692f3..c9ec8db 100644 --- a/lib/framework.dart +++ b/lib/framework.dart @@ -13,5 +13,6 @@ library framework; export 'src/framework/buffers.dart'; export 'src/framework/converters.dart'; export 'src/framework/dart/buffers.dart'; +export 'src/framework/dart/filters.dart'; export 'src/framework/filters.dart'; export 'src/framework/sinks.dart'; diff --git a/lib/src/brotli/decoder.dart b/lib/src/brotli/decoder.dart index 5fcbba5..b5bbdb7 100644 --- a/lib/src/brotli/decoder.dart +++ b/lib/src/brotli/decoder.dart @@ -5,6 +5,8 @@ import 'dart:convert'; import 'dart:ffi'; +import 'package:es_compression/src/framework/native/filters.dart'; + import '../framework/buffers.dart'; import '../framework/converters.dart'; import '../framework/filters.dart'; @@ -56,6 +58,7 @@ class BrotliDecoder extends CodecConverter { } } +/// Brotli decoding sink internal implementation. class _BrotliDecoderSink extends CodecSink { _BrotliDecoderSink._( ByteConversionSink sink, bool ringBufferReallocation, bool largeWindow) @@ -63,16 +66,18 @@ class _BrotliDecoderSink extends CodecSink { _makeBrotliDecompressFilter(ringBufferReallocation, largeWindow)); } -class _BrotliDecompressFilter extends CodecFilter, - NativeCodecBuffer, _BrotliDecodingResult> { +/// Internal filter that decompresses brotli bytes. +class _BrotliDecompressFilter extends NativeCodecFilterBase { /// Dispatcher to make calls via FFI to brotli shared library final BrotliDispatcher _dispatcher = BrotliDispatcher(); + /// Option holder. final List parameters = List(5); /// Native brotli state object BrotliDecoderState _brotliState; + /// Construct an [_BrotliDecompressFilter] with the supplied options. _BrotliDecompressFilter( {bool ringBufferReallocation = true, bool largeWindow = false, @@ -92,12 +97,6 @@ class _BrotliDecompressFilter extends CodecFilter, : BrotliConstants.BROTLI_FALSE; } - @override - CodecBufferHolder, NativeCodecBuffer> newBufferHolder( - int length) { - return NativeCodecBufferHolder(length); - } - /// Return [:true:] if there is more data to process, [:false:] otherwise. @override bool hasMoreToProcess() { @@ -127,8 +126,12 @@ class _BrotliDecompressFilter extends CodecFilter, return 0; } + /// Perform decompression. + /// + /// Answer an [_BrotliDecodingResult] that store how much was read, written + /// and the next read state. @override - _BrotliDecodingResult doProcessing( + CodecResult doProcessing( NativeCodecBuffer inputBuffer, NativeCodecBuffer outputBuffer) { final result = _dispatcher.callBrotliDecoderDecompressStream( _brotliState, @@ -142,11 +145,6 @@ class _BrotliDecompressFilter extends CodecFilter, return _BrotliDecodingResult(read, written, nextReadState); } - @override - int doFlush(CodecBuffer outputBuffer) { - return 0; - } - @override int doFinalize(CodecBuffer outputBuffer) { if (!_dispatcher.callBrotliDecoderIsFinished(_brotliState)) { diff --git a/lib/src/brotli/encoder.dart b/lib/src/brotli/encoder.dart index 606c438..7e995e1 100644 --- a/lib/src/brotli/encoder.dart +++ b/lib/src/brotli/encoder.dart @@ -6,6 +6,8 @@ import 'dart:convert'; import 'dart:ffi'; import 'dart:math'; +import 'package:es_compression/src/framework/native/filters.dart'; + import '../framework/buffers.dart'; import '../framework/converters.dart'; import '../framework/filters.dart'; @@ -126,6 +128,7 @@ class BrotliEncoder extends CodecConverter { } } +/// Brotli encoding sink internal implementation. class _BrotliEncoderSink extends CodecSink { _BrotliEncoderSink._( ByteConversionSink sink, @@ -158,16 +161,17 @@ class _BrotliEncoderSink extends CodecSink { /// This filter contains the implementation details for the usage of the native /// brotli API bindings. -class _BrotliCompressFilter extends CodecFilter, - NativeCodecBuffer, _BrotliEncodingResult> { +class _BrotliCompressFilter extends NativeCodecFilterBase { /// Dispatcher to make calls via FFI to brotli shared library final BrotliDispatcher _dispatcher = BrotliDispatcher(); + /// Option holder. final List parameters = List(10); /// Native brotli context object BrotliEncoderState _brotliState; + /// Construct an [_BrotliCompressFilter] with the provided options. _BrotliCompressFilter( {int level, int mode, @@ -199,12 +203,6 @@ class _BrotliCompressFilter extends CodecFilter, parameters[BrotliConstants.BROTLI_PARAM_NDIRECT] = directDistanceCodeCount; } - @override - CodecBufferHolder, NativeCodecBuffer> newBufferHolder( - int length) { - return NativeCodecBufferHolder(length); - } - /// Init the filter /// /// Provide appropriate buffer lengths to codec builders @@ -238,7 +236,7 @@ class _BrotliCompressFilter extends CodecFilter, /// /// Return an [_BrotliEncodingResult] which describes the amount read/write @override - _BrotliEncodingResult doProcessing( + CodecResult doProcessing( NativeCodecBuffer inputBuffer, NativeCodecBuffer outputBuffer) { final result = _dispatcher.callBrotliEncoderCompressStream( _brotliState, diff --git a/lib/src/framework/dart/filters.dart b/lib/src/framework/dart/filters.dart new file mode 100644 index 0000000..a8643c7 --- /dev/null +++ b/lib/src/framework/dart/filters.dart @@ -0,0 +1,59 @@ +import '../buffers.dart'; +import '../filters.dart'; +import 'buffers.dart'; + +/// Provides a base-class for codec filters that need to use Dart heap-allocated +/// buffers instead of ffi-based buffers. +abstract class DartCodecFilterBase + extends CodecFilter { + /// Constructor which allows the user to set the input/output buffer lengths. + DartCodecFilterBase({int inputBufferLength, int outputBufferLength}) + : super( + inputBufferLength: inputBufferLength, + outputBufferLength: outputBufferLength); + + /// Return a [DartCodecBufferHolder] with the intended [length]. + @override + CodecBufferHolder newBufferHolder( + int length) { + return DartCodecBufferHolder(length); + } + + /// Init the filter. + /// + /// The default behavior is to return 0 for the number of bytes read from + /// the input [bytes]. + @override + int doInit( + CodecBufferHolder inputBufferHolder, + CodecBufferHolder outputBufferHolder, + List bytes, + int start, + int end) { + return 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; + } + + /// 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; + } + + /// Perform tear-down procedures. + /// + /// The default behavior is to take no action. + @override + void doClose() {} +} diff --git a/lib/src/framework/filters.dart b/lib/src/framework/filters.dart index 0675fbd..7395f86 100644 --- a/lib/src/framework/filters.dart +++ b/lib/src/framework/filters.dart @@ -34,11 +34,8 @@ enum CodecFilterState { /// algorithms and direct the processing of data. /// /// Generics: -/// The [CodecFilter] has both the [CodecBuffer] and the [CodecResult] as -/// generic types. /// [P] defines the type to use for the [CodecBuffer]'s memory pointer. /// [CB] is the implementation type for an abstract [CodecBuffer] of type [P] -/// [CR] is the implementation type for a [CodecResult] /// /// A [CodecFilter] contains two buffers. /// An buffer [_inputBuffer] to incoming bytes to process. @@ -47,8 +44,7 @@ enum CodecFilterState { /// A [CodecFilter] also maintains a [state] which can help /// implementations know what part of the lifecycle the filter is in /// (i.e. processing vs closed) -abstract class CodecFilter, - CR extends CodecResult> { +abstract class CodecFilter> { /// Buffer holder for the input buffer CodecBufferHolder _inputBufferHolder; @@ -160,7 +156,7 @@ abstract class CodecFilter, /// Perform a coder/decoder routine where the bytes from the incoming buffer /// are processed by the algorithm and the resulting processed bytes are /// placed in the output buffer - CR _codeOrDecode() { + CodecResult _codeOrDecode() { final result = doProcessing(_checkBuffer(_inputBuffer), _checkBuffer(_outputBuffer)); if (result.adjustBufferCounts) { @@ -294,7 +290,7 @@ abstract class CodecFilter, /// /// Return a [CodecResult] describing the number of bytes read/written during /// the processing routine. - CR doProcessing(CB inputBuffer, CB outputBuffer); + CodecResult doProcessing(CB inputBuffer, CB outputBuffer); /// Subclass Responsibility: Perform algorithm-specific flush. /// @@ -334,8 +330,6 @@ abstract class CodecFilter, } /// Represents the result of encode/decode routines. -/// -/// This is a generic type required by a [CodecFilter]. class CodecResult { /// Number of bytes read by codec routine final int readCount; diff --git a/lib/src/framework/native/filters.dart b/lib/src/framework/native/filters.dart new file mode 100644 index 0000000..f17e87a --- /dev/null +++ b/lib/src/framework/native/filters.dart @@ -0,0 +1,61 @@ +import 'dart:ffi'; + +import '../buffers.dart'; +import '../filters.dart'; +import 'buffers.dart'; + +/// Provides a base-class for codec filters that need to use Dart heap-allocated +/// buffers instead of ffi-based buffers. +abstract class NativeCodecFilterBase + extends CodecFilter, NativeCodecBuffer> { + /// Constructor which allows the user to set the input/output buffer lengths. + NativeCodecFilterBase({int inputBufferLength, int outputBufferLength}) + : super( + inputBufferLength: inputBufferLength, + outputBufferLength: outputBufferLength); + + /// Return a [DartCodecBufferHolder] with the intended [length]. + @override + CodecBufferHolder, NativeCodecBuffer> newBufferHolder( + int length) { + return NativeCodecBufferHolder(length); + } + + /// Init the filter. + /// + /// The default behavior is to return 0 for the number of bytes read from + /// the input [bytes]. + @override + int doInit( + CodecBufferHolder, NativeCodecBuffer> inputBufferHolder, + CodecBufferHolder, NativeCodecBuffer> outputBufferHolder, + List bytes, + int start, + int end) { + return 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; + } + + /// 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; + } + + /// Perform tear-down procedures. + /// + /// The default behavior is to take no action. + @override + void doClose() {} +} diff --git a/lib/src/lz4/decoder.dart b/lib/src/lz4/decoder.dart index bff0123..511fc2e 100644 --- a/lib/src/lz4/decoder.dart +++ b/lib/src/lz4/decoder.dart @@ -6,6 +6,8 @@ import 'dart:convert'; import 'dart:ffi'; import 'dart:math'; +import 'package:es_compression/src/framework/native/filters.dart'; + import '../framework/buffers.dart'; import '../framework/converters.dart'; import '../framework/filters.dart'; @@ -42,6 +44,7 @@ class Lz4Decoder extends CodecConverter { } } +/// Lz4 decoding sink internal implementation. class _Lz4DecoderSink extends CodecSink { _Lz4DecoderSink._( ByteConversionSink sink, int inputBufferLength, int outputBufferLength) @@ -49,8 +52,8 @@ class _Lz4DecoderSink extends CodecSink { sink, _Lz4DecompressFilter(inputBufferLength, outputBufferLength)); } -class _Lz4DecompressFilter - extends CodecFilter, NativeCodecBuffer, _Lz4DecodingResult> { +/// Internal filter that decompresses lz4 bytes. +class _Lz4DecompressFilter extends NativeCodecFilterBase { /// Dispatcher to make calls via FFI to lz4 shared library final Lz4Dispatcher _dispatcher = Lz4Dispatcher(); @@ -71,12 +74,6 @@ class _Lz4DecompressFilter _options = _dispatcher.library.newDecompressOptions(); } - @override - CodecBufferHolder, NativeCodecBuffer> newBufferHolder( - int length) { - return NativeCodecBufferHolder(length); - } - /// Init the filter /// /// 1. Provide appropriate buffer lengths to codec builders @@ -113,8 +110,12 @@ class _Lz4DecompressFilter return numBytes; } + /// Perform decompression. + /// + /// Answer an [_Lz4DecodingResult] that store how much was read, written and + /// how many 'srcSize' bytes are expected for the next call. @override - _Lz4DecodingResult doProcessing( + CodecResult doProcessing( NativeCodecBuffer inputBuffer, NativeCodecBuffer outputBuffer) { final result = _dispatcher.callLz4FDecompress( _ctx, @@ -129,16 +130,7 @@ class _Lz4DecompressFilter return _Lz4DecodingResult(read, written, hint); } - @override - int doFlush(CodecBuffer outputBuffer) { - return 0; - } - - @override - int doFinalize(CodecBuffer outputBuffer) { - return 0; - } - + /// Free memory and release the dispatcher. @override void doClose() { _destroyContext(); diff --git a/lib/src/lz4/encoder.dart b/lib/src/lz4/encoder.dart index 0d5a481..3545b93 100644 --- a/lib/src/lz4/encoder.dart +++ b/lib/src/lz4/encoder.dart @@ -6,6 +6,8 @@ import 'dart:convert'; import 'dart:ffi'; import 'dart:math'; +import 'package:es_compression/src/framework/native/filters.dart'; + import '../framework/buffers.dart'; import '../framework/converters.dart'; import '../framework/filters.dart'; @@ -104,7 +106,7 @@ class Lz4Encoder extends CodecConverter { } } -/// LZ4 codec sink impl +/// Lz4 encoding sink internal implementation. class _Lz4EncoderSink extends CodecSink { _Lz4EncoderSink._( ByteConversionSink sink, @@ -133,8 +135,7 @@ class _Lz4EncoderSink extends CodecSink { /// This filter contains the implementation details for the usage of the native /// lz4 API bindings. -class _Lz4CompressFilter - extends CodecFilter, NativeCodecBuffer, _Lz4EncodingResult> { +class _Lz4CompressFilter extends NativeCodecFilterBase { /// Dispatcher to make calls via FFI to lz4 shared library final Lz4Dispatcher _dispatcher = Lz4Dispatcher(); @@ -147,6 +148,7 @@ class _Lz4CompressFilter /// Native lz4 compress options Lz4CompressOptions _options; + /// Construct the [_Lz4CompressFilter] with the optional parameters. _Lz4CompressFilter( {int level, bool fastAcceleration, @@ -171,12 +173,6 @@ class _Lz4CompressFilter optimizeForCompression: optimizeForCompression); } - @override - CodecBufferHolder, NativeCodecBuffer> newBufferHolder( - int length) { - return NativeCodecBufferHolder(length); - } - /// Init the filter /// /// 1. Provide appropriate buffer lengths to codec builders @@ -226,9 +222,9 @@ class _Lz4CompressFilter /// and put the resulting encoded bytes into [outputBuffer] of length /// [outputBuffer.unwrittenCount]. /// - /// Return an [_Lz4EncodingResult] which describes the amount read/write + /// Return an [CodecResult] which describes the amount read/write @override - _Lz4EncodingResult doProcessing( + CodecResult doProcessing( NativeCodecBuffer inputBuffer, NativeCodecBuffer outputBuffer) { final writtenCount = _dispatcher.callLz4FCompressUpdate( _ctx, @@ -237,7 +233,7 @@ class _Lz4CompressFilter inputBuffer.readPtr, inputBuffer.unreadCount, _options); - return _Lz4EncodingResult(inputBuffer.unreadCount, writtenCount); + return CodecResult(inputBuffer.unreadCount, writtenCount); } /// Lz4 finalize implementation. @@ -354,9 +350,3 @@ CodecFilter _makeLz4CompressFilter( inputBufferLength: inputBufferLength, outputBufferLength: outputBufferLength); } - -/// Result object for an Lz4 Encoding operation -class _Lz4EncodingResult extends CodecResult { - const _Lz4EncodingResult(int bytesRead, int bytesWritten) - : super(bytesRead, bytesWritten); -} diff --git a/lib/src/zstd/decoder.dart b/lib/src/zstd/decoder.dart index 9a0230d..c7cf96c 100644 --- a/lib/src/zstd/decoder.dart +++ b/lib/src/zstd/decoder.dart @@ -6,6 +6,8 @@ import 'dart:convert'; import 'dart:ffi'; import 'dart:math'; +import 'package:es_compression/src/framework/native/filters.dart'; + import '../framework/buffers.dart'; import '../framework/converters.dart'; import '../framework/filters.dart'; @@ -29,7 +31,7 @@ class ZstdDecoder extends CodecConverter { /// Length in bytes of the buffer used for processed output data. final int outputBufferLength; - /// Construct an [ZstdDecoder] + /// Construct an [ZstdDecoder]. ZstdDecoder( {this.inputBufferLength = defaultInputBufferLength, this.outputBufferLength = defaultOutputBufferLength}); @@ -41,6 +43,7 @@ class ZstdDecoder extends CodecConverter { } } +/// Zstd decoding sink internal implementation. class _ZstdDecoderSink extends CodecSink { _ZstdDecoderSink._( ByteConversionSink sink, int inputBufferLength, int outputBufferLength) @@ -48,25 +51,20 @@ class _ZstdDecoderSink extends CodecSink { sink, _ZstdDecompressFilter(inputBufferLength, outputBufferLength)); } -class _ZstdDecompressFilter extends CodecFilter, - NativeCodecBuffer, _ZstdDecodingResult> { +/// Internal filter that decompresses lz4 bytes. +class _ZstdDecompressFilter extends NativeCodecFilterBase { /// Dispatcher to make calls via FFI to zstd shared library final ZstdDispatcher _dispatcher = ZstdDispatcher(); /// Native zstd context object ZstdDStream _dStream; + /// Construct the [_ZstdDecompressFilter] with the optional parameters. _ZstdDecompressFilter(int inputBufferLength, int outputBufferLength) : super( inputBufferLength: inputBufferLength, outputBufferLength: outputBufferLength); - @override - CodecBufferHolder, NativeCodecBuffer> newBufferHolder( - int length) { - return NativeCodecBufferHolder(length); - } - /// Init the filter /// /// Provide appropriate buffer lengths to codec builders @@ -94,8 +92,12 @@ class _ZstdDecompressFilter extends CodecFilter, return 0; } + /// Perform decompression. + /// + /// Answer an [_ZstdDecodingResult] that store how much was read, written and + /// how many 'srcSize' bytes are expected for the next call. @override - _ZstdDecodingResult doProcessing( + CodecResult doProcessing( NativeCodecBuffer inputBuffer, NativeCodecBuffer outputBuffer) { final result = _dispatcher.callZstdDecompressStream( _dStream, @@ -109,16 +111,6 @@ class _ZstdDecompressFilter extends CodecFilter, return _ZstdDecodingResult(read, written, hint); } - @override - int doFlush(CodecBuffer outputBuffer) { - return 0; - } - - @override - int doFinalize(CodecBuffer outputBuffer) { - return 0; - } - /// Release zstd resources @override void doClose() { diff --git a/lib/src/zstd/encoder.dart b/lib/src/zstd/encoder.dart index 042f47d..4c6034d 100644 --- a/lib/src/zstd/encoder.dart +++ b/lib/src/zstd/encoder.dart @@ -6,6 +6,8 @@ import 'dart:convert'; import 'dart:ffi'; import 'dart:math'; +import 'package:es_compression/src/framework/native/filters.dart'; + import '../framework/buffers.dart'; import '../framework/converters.dart'; import '../framework/filters.dart'; @@ -58,6 +60,7 @@ class ZstdEncoder extends CodecConverter { } } +/// Zstd encoding sink internal implementation. class _ZstdEncoderSink extends CodecSink { _ZstdEncoderSink._(ByteConversionSink sink, int level, int inputBufferLength, int outputBufferLength) @@ -69,8 +72,7 @@ class _ZstdEncoderSink extends CodecSink { /// This filter contains the implementation details for the usage of the native /// zstd API bindings. -class _ZstdCompressFilter extends CodecFilter, NativeCodecBuffer, - _ZstdEncodingResult> { +class _ZstdCompressFilter extends NativeCodecFilterBase { /// Dispatcher to make calls via FFI to zstd shared library final ZstdDispatcher _dispatcher = ZstdDispatcher(); @@ -80,6 +82,7 @@ class _ZstdCompressFilter extends CodecFilter, NativeCodecBuffer, /// Native zstd context object ZstdCStream _cStream; + /// Construct the [_ZstdCompressFilter] with the optional parameters. _ZstdCompressFilter( {int level, int inputBufferLength, int outputBufferLength}) : level = level, @@ -87,12 +90,6 @@ class _ZstdCompressFilter extends CodecFilter, NativeCodecBuffer, inputBufferLength: inputBufferLength, outputBufferLength: outputBufferLength); - @override - CodecBufferHolder, NativeCodecBuffer> newBufferHolder( - int length) { - return NativeCodecBufferHolder(length); - } - /// Init the filter /// /// Provide appropriate buffer lengths to codec builders @@ -135,7 +132,7 @@ class _ZstdCompressFilter extends CodecFilter, NativeCodecBuffer, /// /// Return an [_ZstdEncodingResult] which describes the amount read/write @override - _ZstdEncodingResult doProcessing( + CodecResult doProcessing( NativeCodecBuffer inputBuffer, NativeCodecBuffer outputBuffer) { final result = _dispatcher.callZstdCompressStream( _cStream, @@ -184,7 +181,8 @@ class _ZstdCompressFilter extends CodecFilter, NativeCodecBuffer, /// Free the native context /// - /// A [FormatException] is thrown if the context is invalid and can not be freed + /// A [FormatException] is thrown if the context is invalid and can not be + /// freed void _destroyCStream() { if (_cStream != null) { try {