compressImage method

  1. @override
Future<Uint8List> compressImage(
  1. String filename,
  2. Uint8List data,
  3. String mineType,
  4. Options opts,
)
override

Implementation

@override
Future<Uint8List> compressImage(
    String filename, Uint8List data, String mineType, Options opts) async {
  var completer = Completer<Uint8List>();

  var file = File(
    [data],
    filename,
    {'type': mineType},
  );

  OptionsBase optionsBase = OptionsBase.fromOptions(opts);

  var value =
      await completerForPromise(imageCompression(file, optionsBase.impl))
          .future;

  var r = FileReader();

  r.readAsArrayBuffer(value);

  r.onLoadEnd.listen((data) {
    completer.complete(r.result as Uint8List);
  });

  return completer.future;
}