react-native-nitro-tar-gzip
v0.0.3
Published
A React Native Nitro module for decompressing Gzip and Tar files.
Maintainers
Readme
React Native Nitro TarGzip
A React Native Nitro module for decompressing Gzip and Tar files.
This library is a rewrite of FWC1994/react-native-gzip library using Nitro modules, Swift and Kotlin.
Like for original library, this is based on following native libraries:
- iOS: NVHTarGzip
- Android: CompressorStreamFactory and ArchiveStreamFactory
The APIs are similare to FWC1994/react-native-gzip ones at the exception of the returned value.
FWC1994/react-native-gzip:- methods did return a string containing the destination path
- methods did throw if errors occured
react-native-nitro-tar-gzip:- methods do return an object containing success and failure info
- methods do not throw if errors occur
Requirements
This library requires:
- Reat-native
0.75or higher - Xcode
16or higher - Android compileSDK
34or higher
Installation
[!IMPORTANT]
This package requiresreact-native-nitro-modulesto be installed first. See react-native-nitro-modules for more information.
First install dependencies:
npm install --save react-native-nitro-tar-gzip react-native-nitro-modulesThen in your project's Podfile add:
pod 'NVHTarGzip', :modular_headers => trueNVHTarGzip requires modular_headers to be used by Swift package manager. If you know how to implement this on module side and remove this requirement, PR appreciated :smile:
Usage
import { unGzip, unGzipTar, unTar } from 'react-native-nitro-tar-gzip';
const sourcePath = `${PATH}/xxx.gz`
const targetPath = `${PATH}/xxx`
// Decompress Gzip
const result = await unGzip(sourcePath, targetPath, true)
// Decompress Tar
const result = await unTar(sourcePath, targetPath, true)
// Decompress Gzip and Tar
const result = await unGzipTar(sourcePath, targetPath, true)
// Handle the decompressing result
if (result.success) {
console.log(result.path)
} else {
console.error(result.error)
}Parameters
| Name | Type | Description | Mandatory | | ---- | ---- | ---- | ---- | | sourcePath | string | compressed source file path | true | | targetPath | string | target file or folder path for decompressed output | true | | force | boolean | whether to overwrite the target path | true |
Returned object
// When method success
{
success: true,
path: 'some_target_path'
}
// When method fails
{
success: false,
reason: 'Reason of the failure'
}