ZstdCodec 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 .decoder:
import 'package:archive/archive.dart';
import 'dart:io';
import 'package:path/path.dart' as p;
final request = await HttpClient()
.getUrl(Uri.parse('https://example.com/data.tar.zst'));
final HttpClientResponse response = await request.close();
await for (final TarEntry entry in response
// also available for xz/zstd/bzip2/tar
.transform(zstdCodec.decoder)
.transform(tarCodec.decoder)) {
final target = p.join('out', entry.name);
if (!p.isWithin('out', target)) continue; // `../` would escape out/
if (entry.type == TarEntryType.file) {
await File(target).create(recursive: true);
await entry.content.pipe(File(target).openWrite());
}
}
Example for .encoder:
import 'dart:io';
import 'package:archive/archive.dart';
final out = File('data.xz').openWrite();
await File('data')
.openRead()
// also available for xz/zstd/bzip2/tar/zip
.transform(xzCodec.encoder)
.pipe(out);
Constructors
-
ZstdCodec({bool verify = true, ZstdDictionary? dictionary, int maxWindowSize = zstdDefaultMaxWindowSize, int level = zstdDefaultLevel, bool frameChecksum = true, ZstdMultithreadOptions<
Object?> ? multithread, bool ultra = false}) -
const
Properties
- decoder → ZstdDecoderConverter
-
Returns the decoder of
this, converting fromTtoS.no setteroverride - dictionary → ZstdDictionary?
-
What a frame may name to reach back into
final
- encoder → ZstdEncoderConverter
-
Returns the encoder from
StoT.no setteroverride - frameChecksum → bool
-
Whether a written frame has an XXH64 of its content
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
inverted
→ Codec<
List< int> , List<int> > -
Inverts
this.no setterinherited - level → int
-
What ZstdEncoderConverter.level uses
final
- maxWindowSize → int
-
Refuses a frame whose window is wider than this. It stops an archive from
requesting an arbitrary allocation
final
-
multithread
→ ZstdMultithreadOptions<
Object?> ? -
Zstd example:
final
- 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 - verify → bool
-
Checks the XXH64 of every frame that has one
final
Methods
-
decode(
List< int> encoded) → List<int> -
Decodes
encodeddata.inherited -
encode(
List< int> input) → List<int> -
Encodes
input.inherited -
fuse<
R> (Codec< List< other) → Codec<int> , R>List< int> , R> -
Fuses
thiswithother.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited