compressFile method

  1. @override
Future<Uint8List> compressFile(
  1. String path,
  2. CompressOptions options
)
override

Compresses an image file from the filesystem.

Takes a file path and applies compression according to options.

Returns compressed image data as Uint8List.

Throws ImageCompressException if the file is not found or compression fails.

Implementation

@override
Future<Uint8List> compressFile(String path, CompressOptions options) async {
  try {
    final result = await methodChannel
        .invokeMethod<Uint8List>('compressFile', {
          'path': path,
          'maxWidth': options.maxWidth,
          'maxHeight': options.maxHeight,
          'quality': options.quality,
        });

    if (result == null) {
      throw ImageCompressException(
        'Platform returned null result',
        'COMPRESSION_FAILED',
      );
    }

    return result;
  } on PlatformException catch (e) {
    throw ImageCompressException(
      e.message ?? 'Image compression failed',
      e.code,
    );
  } catch (e) {
    throw ImageCompressException(
      'Unexpected error during compression: $e',
      'COMPRESSION_FAILED',
    );
  }
}