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) {
      debugPrint(
        'Platform returned null result for compressFile, returning original file bytes',
      );
      return Uint8List(0);
    }

    return result;
  } on PlatformException catch (e) {
    debugPrint(
      'Platform exception during compressFile: ${e.message} (${e.code})',
    );
    return Uint8List(0);
  } catch (e) {
    debugPrint('Unexpected error during compressFile: $e');
    return Uint8List(0);
  }
}