brotliEncodeFile function

Future<void> brotliEncodeFile(
  1. String path,
  2. Uint8List input, {
  3. BrotliEncodeOptions options = const BrotliEncodeOptions(),
  4. bool create = true,
})

Compresses input and writes the stream to path.

create controls whether a missing file is created. An existing file is truncated to the compressed length.

Implementation

Future<void> brotliEncodeFile(
  String path,
  Uint8List input, {
  BrotliEncodeOptions options = const BrotliEncodeOptions(),
  bool create = true,
}) async {
  final compressed = brotliCompress(input, options: options);
  final file = await openBytesFile(path, create: create);
  try {
    await file.writeAt(0, compressed);
    await file.truncate(compressed.length);
    await file.flush();
  } finally {
    await file.close();
  }
}