I've been dipping my toes into JSI and C lately and, as a result, I got to build a small package called react-native-lz4. It’s a library for fast file compression in React Native using the LZ4 algorithm written in C.
It is still experimental as I'm still polishing the error handling and extending its API but it can already be used (with caution!)
Package: https://github.com/mateoguzmana/react-native-lz4
You can learn more about LZ4 on its website: https://lz4.org/
The package supports both old and new architecture, and currently exposes two main functions to compress and decompress any type of file.
Basic example:
import { compressFile, decompressFile } from 'react-native-lz4'; function onProgress(processedSize: number, totalSize: number) { // e.g. { processedSize: 50, totalSize: 100, progress: '50%' } console.log({ processedSize, totalSize, progress: `${Math.round((processedSize / totalSize) * 100)}%`, }); } const compressionResult = await compressFile( 'path/to/file', 'path/to/output', onProgress ); const decompressionResult = await decompressFile( 'path/to/file', 'path/to/output', onProgress ); console.log(compressionResult); // { success: true, message: 'File compressed successfully', originalSize: 100, finalSize: 50 } console.log(decompressionResult); // { success: true, message: 'File decompressed successfully', originalSize: 50, finalSize: 100 }
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3