wrap static method
Uint8List
wrap(
- Uint8List bytes, {
- required XcfEnvelope envelope,
- int maxOutputBytes = 512 * 1024 * 1024,
Wraps raw XCF bytes; inner tile compression and metadata stay unchanged.
Implementation
static Uint8List wrap(Uint8List bytes, {required XcfEnvelope envelope, int maxOutputBytes = 512 * 1024 * 1024}) {
if (maxOutputBytes < 0) {
throw ArgumentError.value(maxOutputBytes, 'maxOutputBytes');
}
if (!XcfCodec.matches(bytes)) {
throw const XcfFormatException('Only plain XCF bytes can be wrapped');
}
final _EnvelopeSink output = _EnvelopeSink(maxOutputBytes);
final z.ByteEncoder? encoder = switch (envelope) {
XcfEnvelope.none => null,
XcfEnvelope.gzip => const z.GzipEncoder(),
XcfEnvelope.bzip2 => const z.Bzip2Encoder(),
XcfEnvelope.xz => const z.XzEncoder(check: z.XzCheck.crc32),
};
try {
if (encoder == null) {
output.add(bytes);
} else {
final ByteConversionSink sink = encoder.startChunkedConversion(output);
sink
..add(bytes)
..close();
}
} on z.ZCodecException catch (error) {
throw XcfFormatException('Cannot encode XCF envelope: $error');
}
return output.bytes.takeBytes();
}