Home > Web Front-end > JS Tutorial > body text

LZ C React Native bindings for an extremely fast compression algorithm

DDD
Release: 2024-10-07 06:22:02
Original
847 people have browsed it

LZ C   React Native bindings for an extremely fast compression algorithm

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 }


Copy after login

The above is the detailed content of LZ C React Native bindings for an extremely fast compression algorithm. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!