Home  >  Article  >  Web Front-end  >  LZ C React Native bindings for an extremely fast compression algorithm

LZ C React Native bindings for an extremely fast compression algorithm

DDD
DDDOriginal
2024-10-07 06:22:02763browse

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 }


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!

Statement:
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