ZstdEncoderConverter class
Codec for compressing and uncompressing data that arrives in pieces,
the way transform from Stream<List<int>> sends it.
Ideal for usage during network downloads/uploads without creating temporary files
Behaviour is identical to gzip and zlib from dart:io, except for
TAR, ZIP and codecs that are used with MultithreadOptions,
which only differ in closing the sink on failure.
ZstdMultithreadOptions is available only for zstdCodec.encoder and
XZMultithreadOptions for xzCodec.decoder.
Please note that onDone may never be called on failure, you have to listen for both onError and onDone to identify the end of stream. Example for .encoder:
Stream<ArchiveFile> filesOf(Directory dir) async* {
await for (final entity in dir.list(recursive: true)) {
if (entity is File) {
final input = InputFileStream(entity.path);
try {
yield ArchiveFile.stream(
p.relative(entity.path, from: dir.path), input);
} finally {
// Runs once the encoder has written the entry, or when it is
// cancelled
await input.close();
}
}
}
}
final upload =
await HttpClient().putUrl(Uri.parse('https://example.com/backup'));
upload.headers.contentType = ContentType('application', 'zstd');
await upload.addStream(filesOf(Directory('data'))
// also available for zip/tar
.transform(zipCodec.encoder) // Stream<ArchiveFile> -> Stream<List<int>>
// also available for zstd/xz/bzip2
.transform(zstdCodec.encoder));
final response = await upload.close();
Constructors
-
ZstdEncoderConverter({int level = zstdDefaultLevel, bool checksum = true, ZstdMultithreadOptions<
Object?> ? multithread, ZstdDictionary? dictionary, int? contentSize, bool ultra = false}) -
const
Properties
- checksum → bool
-
Whether the frame has an XXH64 of its content
final
- contentSize → int?
-
Streamed frame has no Frame_Content_Size, so reader has to decode whole
frame to learn its size. Pass input length here to write that size
final
- dictionary → ZstdDictionary?
-
Placed before the content, as ZstdChunkedEncoder.dictionary describes
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- level → int
-
final
-
multithread
→ ZstdMultithreadOptions<
Object?> ? -
startChunkedConversioncannot take this option. Its sink writes its output before it returns, and a worker answers laterfinal - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- ultra → bool
-
Allows levels 20 to 22 when
contentSizeis not given, aszstd --ultradoes. Without it they are reduced to 19: with unknown size level 22 sizes its tables for a 128 MB window and took 655 MB on 100 bytes of input, wherezstd -22 --ultratook 707 MB. WithcontentSizethe tables follow the input size and this has no effect.final
Methods
-
bind(
Stream< List< stream) → Stream<int> >List< int> > -
A stream hears a failure once. The sink throws it again on every later
call, so the input after it is dropped here, as gzip and zlib in dart:io
drop it
override
-
cast<
RS, RT> () → Converter< RS, RT> -
Provides a
Converter<RS, RT>view of this stream transformer.inherited -
convert(
List< int> input) → List<int> -
Converts
inputand returns the result of the conversion.inherited -
fuse<
TT> (Converter< List< other) → Converter<int> , TT>List< int> , TT> -
Fuses
thiswithother.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
startChunkedConversion(
Sink< List< sink) → ByteConversionSinkint> > -
Starts a chunked conversion.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited