@javascriptcommon/react-native-xz 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +13 -8
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/xz/XzModule.kt +7 -8
- package/android/src/main/java/com/xz/XzPackage.kt +24 -7
- package/ios/Xz.h +2 -9
- package/ios/Xz.mm +20 -0
- package/ios/Xz.swift +0 -17
- package/package.json +6 -6
- package/react-native-xz.podspec +3 -25
- package/src/NativeXz.ts +9 -0
- package/src/index.ts +4 -26
package/android/build.gradle
CHANGED
|
@@ -4,21 +4,26 @@ buildscript {
|
|
|
4
4
|
mavenCentral()
|
|
5
5
|
}
|
|
6
6
|
dependencies {
|
|
7
|
-
classpath "com.android.tools.build:gradle:
|
|
8
|
-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.
|
|
7
|
+
classpath "com.android.tools.build:gradle:8.2.2"
|
|
8
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22"
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
apply plugin: "com.android.library"
|
|
13
13
|
apply plugin: "kotlin-android"
|
|
14
|
+
apply plugin: "com.facebook.react"
|
|
15
|
+
|
|
16
|
+
def safeExtGet(prop, fallback) {
|
|
17
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
android {
|
|
16
21
|
namespace "com.xz"
|
|
17
|
-
compileSdkVersion 34
|
|
22
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 34)
|
|
18
23
|
|
|
19
24
|
defaultConfig {
|
|
20
|
-
minSdkVersion
|
|
21
|
-
targetSdkVersion 34
|
|
25
|
+
minSdkVersion safeExtGet('minSdkVersion', 24)
|
|
26
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 34)
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
sourceSets {
|
|
@@ -28,12 +33,12 @@ android {
|
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
compileOptions {
|
|
31
|
-
sourceCompatibility JavaVersion.
|
|
32
|
-
targetCompatibility JavaVersion.
|
|
36
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
37
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
kotlinOptions {
|
|
36
|
-
jvmTarget = "
|
|
41
|
+
jvmTarget = "17"
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
|
|
@@ -2,9 +2,8 @@ package com.xz
|
|
|
2
2
|
|
|
3
3
|
import android.util.Log
|
|
4
4
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
-
import com.facebook.react.bridge.ReactMethod
|
|
7
5
|
import com.facebook.react.bridge.Promise
|
|
6
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
8
7
|
import org.tukaani.xz.XZInputStream
|
|
9
8
|
import java.io.File
|
|
10
9
|
import java.io.FileInputStream
|
|
@@ -14,16 +13,17 @@ import kotlinx.coroutines.CoroutineScope
|
|
|
14
13
|
import kotlinx.coroutines.Dispatchers
|
|
15
14
|
import kotlinx.coroutines.launch
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
@ReactModule(name = XzModule.NAME)
|
|
17
|
+
class XzModule(reactContext: ReactApplicationContext) : NativeXzSpec(reactContext) {
|
|
18
18
|
|
|
19
19
|
companion object {
|
|
20
|
+
const val NAME = "Xz"
|
|
20
21
|
private const val TAG = "XzNative"
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
override fun getName(): String =
|
|
24
|
+
override fun getName(): String = NAME
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
fun decompressFile(inputPath: String, outputPath: String, promise: Promise) {
|
|
26
|
+
override fun decompressFile(inputPath: String, outputPath: String, promise: Promise) {
|
|
27
27
|
Log.d(TAG, "decompressFile called, input: $inputPath, output: $outputPath")
|
|
28
28
|
CoroutineScope(Dispatchers.IO).launch {
|
|
29
29
|
try {
|
|
@@ -56,8 +56,7 @@ class XzModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModu
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
fun decompressToString(inputPath: String, promise: Promise) {
|
|
59
|
+
override fun decompressToString(inputPath: String, promise: Promise) {
|
|
61
60
|
Log.d(TAG, "decompressToString called, input: $inputPath")
|
|
62
61
|
CoroutineScope(Dispatchers.IO).launch {
|
|
63
62
|
try {
|
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
package com.xz
|
|
2
2
|
|
|
3
|
-
import com.facebook.react.
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
4
|
import com.facebook.react.bridge.NativeModule
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import com.facebook.react.
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
8
|
|
|
8
|
-
class XzPackage :
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
class XzPackage : BaseReactPackage() {
|
|
10
|
+
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == XzModule.NAME) {
|
|
13
|
+
XzModule(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
11
17
|
}
|
|
12
18
|
|
|
13
|
-
override fun
|
|
14
|
-
return
|
|
19
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
20
|
+
return ReactModuleInfoProvider {
|
|
21
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
22
|
+
moduleInfos[XzModule.NAME] = ReactModuleInfo(
|
|
23
|
+
XzModule.NAME,
|
|
24
|
+
XzModule.NAME,
|
|
25
|
+
false, // canOverrideExistingModule
|
|
26
|
+
false, // needsEagerInit
|
|
27
|
+
false, // isCxxModule
|
|
28
|
+
true // isTurboModule
|
|
29
|
+
)
|
|
30
|
+
moduleInfos
|
|
31
|
+
}
|
|
15
32
|
}
|
|
16
33
|
}
|
package/ios/Xz.h
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
+
// This header is only used for TurboModule conformance
|
|
1
2
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
-
#import
|
|
3
|
-
|
|
4
|
-
@interface Xz : NSObject <NativeXzSpec>
|
|
5
|
-
#else
|
|
6
|
-
#import <React/RCTBridgeModule.h>
|
|
7
|
-
|
|
8
|
-
@interface Xz : NSObject <RCTBridgeModule>
|
|
3
|
+
#import <RNXzSpec/RNXzSpec.h>
|
|
9
4
|
#endif
|
|
10
|
-
|
|
11
|
-
@end
|
package/ios/Xz.mm
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
2
|
|
|
3
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
4
|
+
#import <RNXzSpec/RNXzSpec.h>
|
|
5
|
+
#import <React/RCTBridge+Private.h>
|
|
6
|
+
#endif
|
|
7
|
+
|
|
3
8
|
@interface RCT_EXTERN_MODULE(Xz, NSObject)
|
|
4
9
|
|
|
5
10
|
RCT_EXTERN_METHOD(decompressFile:(NSString *)inputPath
|
|
@@ -12,3 +17,18 @@ RCT_EXTERN_METHOD(decompressToString:(NSString *)inputPath
|
|
|
12
17
|
reject:(RCTPromiseRejectBlock)reject)
|
|
13
18
|
|
|
14
19
|
@end
|
|
20
|
+
|
|
21
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
22
|
+
@interface Xz () <NativeXzSpec>
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation Xz (TurboModule)
|
|
26
|
+
|
|
27
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
28
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
29
|
+
{
|
|
30
|
+
return std::make_shared<facebook::react::NativeXzSpecJSI>(params);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@end
|
|
34
|
+
#endif
|
package/ios/Xz.swift
CHANGED
|
@@ -11,25 +11,17 @@ class Xz: NSObject {
|
|
|
11
11
|
|
|
12
12
|
@objc
|
|
13
13
|
func decompressFile(_ inputPath: String, outputPath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
14
|
-
print("[Xz Native] decompressFile called, input: \(inputPath), output: \(outputPath)")
|
|
15
14
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
16
15
|
do {
|
|
17
16
|
let inputURL = URL(fileURLWithPath: inputPath)
|
|
18
17
|
let outputURL = URL(fileURLWithPath: outputPath)
|
|
19
18
|
|
|
20
|
-
print("[Xz Native] Reading compressed file...")
|
|
21
19
|
let compressedData = try Data(contentsOf: inputURL)
|
|
22
|
-
print("[Xz Native] Compressed size: \(compressedData.count) bytes")
|
|
23
|
-
|
|
24
|
-
print("[Xz Native] Decompressing...")
|
|
25
20
|
let decompressedData = try XZArchive.unarchive(archive: compressedData)
|
|
26
|
-
print("[Xz Native] Decompressed size: \(decompressedData.count) bytes")
|
|
27
21
|
|
|
28
22
|
try decompressedData.write(to: outputURL)
|
|
29
|
-
print("[Xz Native] Written to output file")
|
|
30
23
|
resolve(outputPath)
|
|
31
24
|
} catch {
|
|
32
|
-
print("[Xz Native] Error: \(error.localizedDescription)")
|
|
33
25
|
reject("XZ_ERROR", "Failed to decompress XZ file: \(error.localizedDescription)", error)
|
|
34
26
|
}
|
|
35
27
|
}
|
|
@@ -37,29 +29,20 @@ class Xz: NSObject {
|
|
|
37
29
|
|
|
38
30
|
@objc
|
|
39
31
|
func decompressToString(_ inputPath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
40
|
-
print("[Xz Native] decompressToString called, input: \(inputPath)")
|
|
41
32
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
42
33
|
do {
|
|
43
34
|
let inputURL = URL(fileURLWithPath: inputPath)
|
|
44
35
|
|
|
45
|
-
print("[Xz Native] Reading compressed file...")
|
|
46
36
|
let compressedData = try Data(contentsOf: inputURL)
|
|
47
|
-
print("[Xz Native] Compressed size: \(compressedData.count) bytes")
|
|
48
|
-
|
|
49
|
-
print("[Xz Native] Decompressing...")
|
|
50
37
|
let decompressedData = try XZArchive.unarchive(archive: compressedData)
|
|
51
|
-
print("[Xz Native] Decompressed size: \(decompressedData.count) bytes")
|
|
52
38
|
|
|
53
39
|
guard let string = String(data: decompressedData, encoding: .utf8) else {
|
|
54
|
-
print("[Xz Native] Error: Failed to decode as UTF-8")
|
|
55
40
|
reject("XZ_ERROR", "Failed to decode decompressed data as UTF-8 string", nil)
|
|
56
41
|
return
|
|
57
42
|
}
|
|
58
43
|
|
|
59
|
-
print("[Xz Native] String length: \(string.count) characters")
|
|
60
44
|
resolve(string)
|
|
61
45
|
} catch {
|
|
62
|
-
print("[Xz Native] Error: \(error.localizedDescription)")
|
|
63
46
|
reject("XZ_ERROR", "Failed to decompress XZ file: \(error.localizedDescription)", error)
|
|
64
47
|
}
|
|
65
48
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@javascriptcommon/react-native-xz",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Native XZ/LZMA2 decompression for React Native",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Native XZ/LZMA2 decompression for React Native (TurboModules)",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
7
7
|
"source": "src/index.ts",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"lzma",
|
|
24
24
|
"lzma2",
|
|
25
25
|
"compression",
|
|
26
|
-
"decompression"
|
|
26
|
+
"decompression",
|
|
27
|
+
"turbomodules"
|
|
27
28
|
],
|
|
28
29
|
"repository": {
|
|
29
30
|
"type": "git",
|
|
@@ -33,13 +34,12 @@
|
|
|
33
34
|
"license": "MIT",
|
|
34
35
|
"peerDependencies": {
|
|
35
36
|
"react": "*",
|
|
36
|
-
"react-native": "
|
|
37
|
+
"react-native": ">=0.71.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/react": "^18.0.0",
|
|
40
|
-
"@types/react-native": "^0.72.0",
|
|
41
41
|
"react": "^18.0.0",
|
|
42
|
-
"react-native": "^0.
|
|
42
|
+
"react-native": "^0.76.0",
|
|
43
43
|
"typescript": "^5.0.0"
|
|
44
44
|
},
|
|
45
45
|
"codegenConfig": {
|
package/react-native-xz.podspec
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
-
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
4
|
|
|
6
5
|
Pod::Spec.new do |s|
|
|
7
6
|
s.name = "react-native-xz"
|
|
@@ -11,33 +10,12 @@ Pod::Spec.new do |s|
|
|
|
11
10
|
s.license = package["license"]
|
|
12
11
|
s.authors = package["author"]
|
|
13
12
|
|
|
14
|
-
s.platforms = { :ios =>
|
|
13
|
+
s.platforms = { :ios => "13.4" }
|
|
15
14
|
s.source = { :git => "https://github.com/Spicy-Sparks/react-native-xz.git", :tag => "#{s.version}" }
|
|
16
15
|
|
|
17
|
-
s.source_files = "ios/**/*.{h,m,mm
|
|
18
|
-
s.swift_version = "5.0"
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
19
17
|
|
|
20
18
|
s.dependency "SWCompression", "~> 4.8"
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
if respond_to?(:install_modules_dependencies, true)
|
|
24
|
-
install_modules_dependencies(s)
|
|
25
|
-
else
|
|
26
|
-
s.dependency "React-Core"
|
|
27
|
-
|
|
28
|
-
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
29
|
-
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
30
|
-
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
31
|
-
s.pod_target_xcconfig = {
|
|
32
|
-
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
33
|
-
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
34
|
-
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
35
|
-
}
|
|
36
|
-
s.dependency "React-Codegen"
|
|
37
|
-
s.dependency "RCT-Folly"
|
|
38
|
-
s.dependency "RCTRequired"
|
|
39
|
-
s.dependency "RCTTypeSafety"
|
|
40
|
-
s.dependency "ReactCommon/turbomodule/core"
|
|
41
|
-
end
|
|
42
|
-
end
|
|
20
|
+
install_modules_dependencies(s)
|
|
43
21
|
end
|
package/src/NativeXz.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
decompressFile(inputPath: string, outputPath: string): Promise<string>;
|
|
6
|
+
decompressToString(inputPath: string): Promise<string>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('Xz');
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const LINKING_ERROR =
|
|
4
|
-
`The package 'react-native-xz' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
-
'- You rebuilt the app after installing the package\n' +
|
|
7
|
-
'- You are not using Expo Go\n'
|
|
8
|
-
|
|
9
|
-
interface XzModule {
|
|
10
|
-
decompressFile(inputPath: string, outputPath: string): Promise<string>
|
|
11
|
-
decompressToString(inputPath: string): Promise<string>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const Xz: XzModule = NativeModules.Xz
|
|
15
|
-
? NativeModules.Xz
|
|
16
|
-
: new Proxy(
|
|
17
|
-
{},
|
|
18
|
-
{
|
|
19
|
-
get() {
|
|
20
|
-
throw new Error(LINKING_ERROR)
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
)
|
|
1
|
+
import NativeXz from './NativeXz';
|
|
24
2
|
|
|
25
3
|
/**
|
|
26
4
|
* Decompress an XZ file to a destination path
|
|
@@ -29,7 +7,7 @@ const Xz: XzModule = NativeModules.Xz
|
|
|
29
7
|
* @returns Promise resolving to the output path
|
|
30
8
|
*/
|
|
31
9
|
export function decompressFile(inputPath: string, outputPath: string): Promise<string> {
|
|
32
|
-
return
|
|
10
|
+
return NativeXz.decompressFile(inputPath, outputPath);
|
|
33
11
|
}
|
|
34
12
|
|
|
35
13
|
/**
|
|
@@ -38,10 +16,10 @@ export function decompressFile(inputPath: string, outputPath: string): Promise<s
|
|
|
38
16
|
* @returns Promise resolving to the decompressed string content
|
|
39
17
|
*/
|
|
40
18
|
export function decompressToString(inputPath: string): Promise<string> {
|
|
41
|
-
return
|
|
19
|
+
return NativeXz.decompressToString(inputPath);
|
|
42
20
|
}
|
|
43
21
|
|
|
44
22
|
export default {
|
|
45
23
|
decompressFile,
|
|
46
24
|
decompressToString,
|
|
47
|
-
}
|
|
25
|
+
};
|