fluttercandies / flutter_image_compress

flutter image compress
MIT License
632 stars 215 forks source link

[Feature request] Return XFile or Path instead of Uint8List for compressions #281

Open ynnob opened 7 months ago

ynnob commented 7 months ago

Platforms

dart, Android, iOS, macOS, Web, Windows, Linux

Description

Return the path to the compressed cache file instead of the Uint8List. At the moment, the compression creates a File in the cache directory and only returns the bytes. There is no way to use the file that has been created in the cache directory by the compression method.

Why

Returning only the bytes of the compressed images forces the user to hold all the bytes in memory or save them as duplicates so we can store a path instead of holding them in memory. In both scenarios, the file is a duplicate because the compression itself already created a file in the cache folder.

This is important if we compress multiple files. The current workflow: -> Select Images -> Compress -> Wait for the user to confirm compression and save to the device.

These lead to duplicate files and unnecessary storage usage if we don't want to hold the files in memory. To avoid the high memory usage, we only store a reference to the file path so we can wait for user input to permanently save the image at a permanent storage location.