@onekeyfe/react-native-zip-archive 3.0.38 → 3.0.40
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/{ZipArchive.podspec → ReactNativeZipArchive.podspec} +12 -3
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +54 -3
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/reactnativeziparchive/ReactNativeZipArchive.kt +139 -0
- package/android/src/main/java/com/margelo/nitro/reactnativeziparchive/ReactNativeZipArchivePackage.kt +22 -0
- package/ios/ReactNativeZipArchive.swift +130 -0
- package/lib/module/ReactNativeZipArchive.nitro.js +4 -0
- package/lib/module/index.js +24 -3
- package/lib/typescript/src/{NativeZipArchive.d.ts → ReactNativeZipArchive.nitro.d.ts} +6 -5
- package/lib/typescript/src/index.d.ts +10 -2
- package/nitro.json +17 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeZipArchiveSpec.cpp +155 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeZipArchiveSpec.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeziparchive/HybridReactNativeZipArchiveSpec.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeziparchive/reactnativeziparchiveOnLoad.kt +35 -0
- package/nitrogen/generated/android/reactnativeziparchive+autolinking.cmake +81 -0
- package/nitrogen/generated/android/reactnativeziparchive+autolinking.gradle +27 -0
- package/nitrogen/generated/android/reactnativeziparchiveOnLoad.cpp +44 -0
- package/nitrogen/generated/android/reactnativeziparchiveOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/ReactNativeZipArchive+autolinking.rb +60 -0
- package/nitrogen/generated/ios/ReactNativeZipArchive-Swift-Cxx-Bridge.cpp +65 -0
- package/nitrogen/generated/ios/ReactNativeZipArchive-Swift-Cxx-Bridge.hpp +209 -0
- package/nitrogen/generated/ios/ReactNativeZipArchive-Swift-Cxx-Umbrella.hpp +46 -0
- package/nitrogen/generated/ios/ReactNativeZipArchiveAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeZipArchiveAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeZipArchiveSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeZipArchiveSpecSwift.hpp +118 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeZipArchiveSpec.swift +61 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeZipArchiveSpec_cxx.swift +233 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeZipArchiveSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeZipArchiveSpec.hpp +69 -0
- package/package.json +22 -17
- package/src/ReactNativeZipArchive.nitro.ts +26 -0
- package/src/index.tsx +47 -4
- package/android/src/main/java/com/rnziparchive/RNZipArchiveModule.kt +0 -158
- package/android/src/main/java/com/rnziparchive/RNZipArchivePackage.kt +0 -33
- package/ios/ZipArchive.h +0 -10
- package/ios/ZipArchive.mm +0 -182
- package/lib/module/NativeZipArchive.js +0 -5
- package/src/NativeZipArchive.ts +0 -13
|
@@ -3,7 +3,7 @@ require "json"
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name = "
|
|
6
|
+
s.name = "ReactNativeZipArchive"
|
|
7
7
|
s.version = package["version"]
|
|
8
8
|
s.summary = package["description"]
|
|
9
9
|
s.homepage = package["homepage"]
|
|
@@ -13,9 +13,18 @@ Pod::Spec.new do |s|
|
|
|
13
13
|
s.platforms = { :ios => min_ios_version_supported }
|
|
14
14
|
s.source = { :git => "https://github.com/OneKeyHQ/app-modules/react-native-zip-archive.git", :tag => "#{s.version}" }
|
|
15
15
|
|
|
16
|
-
s.source_files =
|
|
16
|
+
s.source_files = [
|
|
17
|
+
"ios/**/*.{swift}",
|
|
18
|
+
"ios/**/*.{m,mm}",
|
|
19
|
+
"cpp/**/*.{hpp,cpp}",
|
|
20
|
+
]
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
# >= 2.5.4 pulls the fix for the zip-slip / symlink path-traversal CVEs
|
|
23
|
+
# (CVE-2023-39139 etc.) — important since OTA unzips downloaded archives.
|
|
24
|
+
s.dependency 'SSZipArchive', '>= 2.5.4'
|
|
25
|
+
|
|
26
|
+
load 'nitrogen/generated/ios/ReactNativeZipArchive+autolinking.rb'
|
|
27
|
+
add_nitrogen_files(s)
|
|
19
28
|
|
|
20
29
|
install_modules_dependencies(s)
|
|
21
30
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
project(reactnativeziparchive)
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
|
|
4
|
+
set(PACKAGE_NAME reactnativeziparchive)
|
|
5
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
7
|
+
|
|
8
|
+
# Define C++ library and add all sources
|
|
9
|
+
add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp)
|
|
10
|
+
|
|
11
|
+
# Add Nitrogen specs :)
|
|
12
|
+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/reactnativeziparchive+autolinking.cmake)
|
|
13
|
+
|
|
14
|
+
# Set up local includes
|
|
15
|
+
include_directories("src/main/cpp")
|
|
16
|
+
|
|
17
|
+
find_library(LOG_LIB log)
|
|
18
|
+
|
|
19
|
+
# Link all libraries together
|
|
20
|
+
target_link_libraries(
|
|
21
|
+
${PACKAGE_NAME}
|
|
22
|
+
${LOG_LIB}
|
|
23
|
+
android # <-- Android core
|
|
24
|
+
)
|
package/android/build.gradle
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
buildscript {
|
|
2
2
|
ext.getExtOrDefault = {name ->
|
|
3
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeZipArchive_' + name]
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
repositories {
|
|
@@ -15,28 +15,78 @@ buildscript {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
def reactNativeArchitectures() {
|
|
19
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
20
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
apply plugin: "com.android.library"
|
|
20
24
|
apply plugin: "kotlin-android"
|
|
25
|
+
apply from: '../nitrogen/generated/android/reactnativeziparchive+autolinking.gradle'
|
|
21
26
|
|
|
22
27
|
apply plugin: "com.facebook.react"
|
|
23
28
|
|
|
24
29
|
def getExtOrIntegerDefault(name) {
|
|
25
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["
|
|
30
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeZipArchive_" + name]).toInteger()
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
android {
|
|
29
|
-
namespace "com.
|
|
34
|
+
namespace "com.margelo.nitro.reactnativeziparchive"
|
|
30
35
|
|
|
31
36
|
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
37
|
|
|
33
38
|
defaultConfig {
|
|
34
39
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
40
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
41
|
+
|
|
42
|
+
externalNativeBuild {
|
|
43
|
+
cmake {
|
|
44
|
+
cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
|
|
45
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
46
|
+
abiFilters (*reactNativeArchitectures())
|
|
47
|
+
|
|
48
|
+
buildTypes {
|
|
49
|
+
debug {
|
|
50
|
+
cppFlags "-O1 -g"
|
|
51
|
+
}
|
|
52
|
+
release {
|
|
53
|
+
cppFlags "-O2"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
externalNativeBuild {
|
|
61
|
+
cmake {
|
|
62
|
+
path "CMakeLists.txt"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
packagingOptions {
|
|
67
|
+
excludes = [
|
|
68
|
+
"META-INF",
|
|
69
|
+
"META-INF/**",
|
|
70
|
+
"**/libc++_shared.so",
|
|
71
|
+
"**/libfbjni.so",
|
|
72
|
+
"**/libjsi.so",
|
|
73
|
+
"**/libfolly_json.so",
|
|
74
|
+
"**/libfolly_runtime.so",
|
|
75
|
+
"**/libglog.so",
|
|
76
|
+
"**/libhermes.so",
|
|
77
|
+
"**/libhermes-executor-debug.so",
|
|
78
|
+
"**/libhermes_executor.so",
|
|
79
|
+
"**/libreactnative.so",
|
|
80
|
+
"**/libreactnativejni.so",
|
|
81
|
+
"**/libturbomodulejsijni.so",
|
|
82
|
+
"**/libreact_nativemodule_core.so",
|
|
83
|
+
"**/libjscexecutor.so"
|
|
84
|
+
]
|
|
36
85
|
}
|
|
37
86
|
|
|
38
87
|
buildFeatures {
|
|
39
88
|
buildConfig true
|
|
89
|
+
prefab true
|
|
40
90
|
}
|
|
41
91
|
|
|
42
92
|
buildTypes {
|
|
@@ -74,4 +124,5 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
|
74
124
|
dependencies {
|
|
75
125
|
implementation "com.facebook.react:react-android"
|
|
76
126
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
127
|
+
implementation project(":react-native-nitro-modules")
|
|
77
128
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
package/android/src/main/java/com/margelo/nitro/reactnativeziparchive/ReactNativeZipArchive.kt
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
package com.margelo.nitro.reactnativeziparchive
|
|
2
|
+
|
|
3
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
4
|
+
import com.margelo.nitro.core.Promise
|
|
5
|
+
import java.io.BufferedInputStream
|
|
6
|
+
import java.io.BufferedOutputStream
|
|
7
|
+
import java.io.File
|
|
8
|
+
import java.io.FileInputStream
|
|
9
|
+
import java.io.FileOutputStream
|
|
10
|
+
import java.util.zip.ZipEntry
|
|
11
|
+
import java.util.zip.ZipFile
|
|
12
|
+
import java.util.zip.ZipInputStream
|
|
13
|
+
import java.util.zip.ZipOutputStream
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Nitro HybridObject implementation of the OneKey zip-archive module.
|
|
17
|
+
*
|
|
18
|
+
* This is a 1:1 port of the previous TurboModule `RNZipArchiveModule.kt`. The
|
|
19
|
+
* underlying archive engine is unchanged: it still uses `java.util.zip`
|
|
20
|
+
* (`ZipInputStream` / `ZipOutputStream` / `ZipFile`) so the on-disk
|
|
21
|
+
* extraction/compression behaviour stays byte-for-byte identical.
|
|
22
|
+
*/
|
|
23
|
+
@DoNotStrip
|
|
24
|
+
class ReactNativeZipArchive : HybridReactNativeZipArchiveSpec() {
|
|
25
|
+
|
|
26
|
+
companion object {
|
|
27
|
+
private const val BUFFER_SIZE = 8192
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun isPasswordProtected(file: String): Promise<Boolean> {
|
|
31
|
+
return Promise.async {
|
|
32
|
+
// java.util.zip does not support password-protected zips natively.
|
|
33
|
+
// Return false as a safe default (matches the previous implementation).
|
|
34
|
+
false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override fun unzip(from: String, to: String): Promise<String> {
|
|
39
|
+
return Promise.async {
|
|
40
|
+
val destDir = File(to)
|
|
41
|
+
if (!destDir.exists()) destDir.mkdirs()
|
|
42
|
+
|
|
43
|
+
ZipInputStream(BufferedInputStream(FileInputStream(from))).use { zis ->
|
|
44
|
+
var entry: ZipEntry? = zis.nextEntry
|
|
45
|
+
while (entry != null) {
|
|
46
|
+
val outFile = File(destDir, entry.name)
|
|
47
|
+
if (entry.isDirectory) {
|
|
48
|
+
outFile.mkdirs()
|
|
49
|
+
} else {
|
|
50
|
+
outFile.parentFile?.mkdirs()
|
|
51
|
+
FileOutputStream(outFile).use { fos ->
|
|
52
|
+
val buffer = ByteArray(BUFFER_SIZE)
|
|
53
|
+
var len: Int
|
|
54
|
+
while (zis.read(buffer).also { len = it } > 0) {
|
|
55
|
+
fos.write(buffer, 0, len)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
zis.closeEntry()
|
|
60
|
+
entry = zis.nextEntry
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
to
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
override fun unzipWithPassword(from: String, to: String, password: String): Promise<String> {
|
|
68
|
+
return Promise.async {
|
|
69
|
+
// java.util.zip does not support password-protected zip extraction.
|
|
70
|
+
throw Exception("Password-protected zip extraction is not supported on Android")
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
override fun zipFolder(from: String, to: String): Promise<String> {
|
|
75
|
+
return Promise.async {
|
|
76
|
+
val sourceDir = File(from)
|
|
77
|
+
FileOutputStream(to).use { fos ->
|
|
78
|
+
ZipOutputStream(BufferedOutputStream(fos)).use { zos ->
|
|
79
|
+
zipDirectory(sourceDir, sourceDir.name, zos)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
to
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
override fun zipFiles(files: Array<String>, to: String): Promise<String> {
|
|
87
|
+
return Promise.async {
|
|
88
|
+
FileOutputStream(to).use { fos ->
|
|
89
|
+
ZipOutputStream(BufferedOutputStream(fos)).use { zos ->
|
|
90
|
+
for (filePath in files) {
|
|
91
|
+
val file = File(filePath)
|
|
92
|
+
if (file.exists()) {
|
|
93
|
+
addFileToZip(file, file.name, zos)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
to
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
override fun getUncompressedSize(path: String): Promise<Double> {
|
|
103
|
+
return Promise.async {
|
|
104
|
+
var totalSize = 0L
|
|
105
|
+
ZipFile(path).use { zipFile ->
|
|
106
|
+
val entries = zipFile.entries()
|
|
107
|
+
while (entries.hasMoreElements()) {
|
|
108
|
+
totalSize += entries.nextElement().size
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
totalSize.toDouble()
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private fun zipDirectory(dir: File, baseName: String, zos: ZipOutputStream) {
|
|
116
|
+
val files = dir.listFiles() ?: return
|
|
117
|
+
for (file in files) {
|
|
118
|
+
val entryName = "$baseName/${file.name}"
|
|
119
|
+
if (file.isDirectory) {
|
|
120
|
+
zipDirectory(file, entryName, zos)
|
|
121
|
+
} else {
|
|
122
|
+
addFileToZip(file, entryName, zos)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private fun addFileToZip(file: File, entryName: String, zos: ZipOutputStream) {
|
|
128
|
+
val entry = ZipEntry(entryName)
|
|
129
|
+
zos.putNextEntry(entry)
|
|
130
|
+
FileInputStream(file).use { fis ->
|
|
131
|
+
val buffer = ByteArray(BUFFER_SIZE)
|
|
132
|
+
var len: Int
|
|
133
|
+
while (fis.read(buffer).also { len = it } > 0) {
|
|
134
|
+
zos.write(buffer, 0, len)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
zos.closeEntry()
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.margelo.nitro.reactnativeziparchive
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
|
+
|
|
8
|
+
class ReactNativeZipArchivePackage : BaseReactPackage() {
|
|
9
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
14
|
+
return ReactModuleInfoProvider { HashMap() }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
companion object {
|
|
18
|
+
init {
|
|
19
|
+
System.loadLibrary("reactnativeziparchive")
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import NitroModules
|
|
3
|
+
import SSZipArchive
|
|
4
|
+
|
|
5
|
+
/// Nitro HybridObject implementation of the OneKey zip-archive module.
|
|
6
|
+
///
|
|
7
|
+
/// This is a 1:1 port of the previous Objective-C `ZipArchive.mm` TurboModule.
|
|
8
|
+
/// The underlying archive engine is unchanged: it still wraps `SSZipArchive`
|
|
9
|
+
/// (`unzipFileAtPath:` / `createZipFileAtPath:` / `payloadSizeForArchiveAtPath:`)
|
|
10
|
+
/// so the on-disk extraction/compression behaviour stays byte-for-byte identical.
|
|
11
|
+
final class ReactNativeZipArchive: HybridReactNativeZipArchiveSpec {
|
|
12
|
+
|
|
13
|
+
// MARK: - isPasswordProtected
|
|
14
|
+
|
|
15
|
+
func isPasswordProtected(file: String) throws -> Promise<Bool> {
|
|
16
|
+
return Promise.async {
|
|
17
|
+
return SSZipArchive.isFilePasswordProtected(atPath: file)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// MARK: - unzip
|
|
22
|
+
|
|
23
|
+
func unzip(from: String, to: String) throws -> Promise<String> {
|
|
24
|
+
return Promise.async {
|
|
25
|
+
var error: NSError?
|
|
26
|
+
let success = SSZipArchive.unzipFile(
|
|
27
|
+
atPath: from,
|
|
28
|
+
toDestination: to,
|
|
29
|
+
preserveAttributes: false,
|
|
30
|
+
overwrite: true,
|
|
31
|
+
password: nil,
|
|
32
|
+
error: &error,
|
|
33
|
+
delegate: nil
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
if success {
|
|
37
|
+
return to
|
|
38
|
+
}
|
|
39
|
+
throw NSError(
|
|
40
|
+
domain: "ZipArchive",
|
|
41
|
+
code: -1,
|
|
42
|
+
userInfo: [
|
|
43
|
+
NSLocalizedDescriptionKey: error?.localizedDescription ?? "unable to unzip"
|
|
44
|
+
]
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// MARK: - unzipWithPassword
|
|
50
|
+
|
|
51
|
+
func unzipWithPassword(from: String, to: String, password: String) throws -> Promise<String> {
|
|
52
|
+
return Promise.async {
|
|
53
|
+
var error: NSError?
|
|
54
|
+
let success = SSZipArchive.unzipFile(
|
|
55
|
+
atPath: from,
|
|
56
|
+
toDestination: to,
|
|
57
|
+
preserveAttributes: false,
|
|
58
|
+
overwrite: true,
|
|
59
|
+
password: password,
|
|
60
|
+
error: &error,
|
|
61
|
+
delegate: nil
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
if success {
|
|
65
|
+
return to
|
|
66
|
+
}
|
|
67
|
+
throw NSError(
|
|
68
|
+
domain: "ZipArchive",
|
|
69
|
+
code: -1,
|
|
70
|
+
userInfo: [NSLocalizedDescriptionKey: "unable to unzip"]
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// MARK: - zipFolder
|
|
76
|
+
|
|
77
|
+
func zipFolder(from: String, to: String) throws -> Promise<String> {
|
|
78
|
+
return Promise.async {
|
|
79
|
+
let success = SSZipArchive.createZipFile(
|
|
80
|
+
atPath: to,
|
|
81
|
+
withContentsOfDirectory: from,
|
|
82
|
+
keepParentDirectory: false,
|
|
83
|
+
withPassword: nil,
|
|
84
|
+
andProgressHandler: nil
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
if success {
|
|
88
|
+
return to
|
|
89
|
+
}
|
|
90
|
+
throw NSError(
|
|
91
|
+
domain: "ZipArchive",
|
|
92
|
+
code: -1,
|
|
93
|
+
userInfo: [NSLocalizedDescriptionKey: "unable to zip"]
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// MARK: - zipFiles
|
|
99
|
+
|
|
100
|
+
func zipFiles(files: [String], to: String) throws -> Promise<String> {
|
|
101
|
+
return Promise.async {
|
|
102
|
+
let success = SSZipArchive.createZipFile(atPath: to, withFilesAtPaths: files)
|
|
103
|
+
|
|
104
|
+
if success {
|
|
105
|
+
return to
|
|
106
|
+
}
|
|
107
|
+
throw NSError(
|
|
108
|
+
domain: "ZipArchive",
|
|
109
|
+
code: -1,
|
|
110
|
+
userInfo: [NSLocalizedDescriptionKey: "unable to zip"]
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// MARK: - getUncompressedSize
|
|
116
|
+
|
|
117
|
+
func getUncompressedSize(path: String) throws -> Promise<Double> {
|
|
118
|
+
return Promise.async {
|
|
119
|
+
// Swift imports `+payloadSizeForArchiveAtPath:error:` as
|
|
120
|
+
// payloadSizeForArchive(atPath:error:) -> NSNumber (non-throwing, keeps the
|
|
121
|
+
// NSErrorPointer because the return is unannotated/non-nullable).
|
|
122
|
+
var error: NSError?
|
|
123
|
+
let wantedFileSize = SSZipArchive.payloadSizeForArchive(atPath: path, error: &error)
|
|
124
|
+
if error == nil {
|
|
125
|
+
return wantedFileSize.doubleValue
|
|
126
|
+
}
|
|
127
|
+
return -1
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
package/lib/module/index.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
const ReactNativeZipArchiveHybridObject = NitroModules.createHybridObject('ReactNativeZipArchive');
|
|
5
|
+
|
|
6
|
+
// Raw HybridObject. Kept exported for compatibility with the previous
|
|
7
|
+
// `export const ZipArchive = NativeZipArchive` shape.
|
|
8
|
+
export const ZipArchive = ReactNativeZipArchiveHybridObject;
|
|
9
|
+
|
|
10
|
+
// Backwards-compatible named function wrappers. These preserve the exact
|
|
11
|
+
// public API (names + signatures) of the previous TurboModule-based release so
|
|
12
|
+
// consumers (e.g. monorepo logger using `import { zip }`) require zero changes.
|
|
13
|
+
|
|
14
|
+
export const isPasswordProtected = file => ReactNativeZipArchiveHybridObject.isPasswordProtected(file);
|
|
15
|
+
export const unzip = (from, to) => ReactNativeZipArchiveHybridObject.unzip(from, to);
|
|
16
|
+
export const unzipWithPassword = (from, to, password) => ReactNativeZipArchiveHybridObject.unzipWithPassword(from, to, password);
|
|
17
|
+
export const zipFolder = (from, to) => ReactNativeZipArchiveHybridObject.zipFolder(from, to);
|
|
18
|
+
export const zipFiles = (files, to) => ReactNativeZipArchiveHybridObject.zipFiles(files, to);
|
|
19
|
+
export const getUncompressedSize = path => ReactNativeZipArchiveHybridObject.getUncompressedSize(path);
|
|
20
|
+
|
|
21
|
+
// `zip` is an alias for `zipFolder` and matches the previous public signature
|
|
22
|
+
// `(source, target) => Promise<string>`. This is the only API the monorepo
|
|
23
|
+
// logger consumes.
|
|
24
|
+
export const zip = (source, target) => ReactNativeZipArchiveHybridObject.zipFolder(source, target);
|
|
25
|
+
|
|
26
|
+
// Backwards-compatible alias for the previously exported `ZipArchiveSpec` type.
|
|
6
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export interface ReactNativeZipArchive extends HybridObject<{
|
|
3
|
+
ios: 'swift';
|
|
4
|
+
android: 'kotlin';
|
|
5
|
+
}> {
|
|
3
6
|
isPasswordProtected(file: string): Promise<boolean>;
|
|
4
7
|
unzip(from: string, to: string): Promise<string>;
|
|
5
8
|
unzipWithPassword(from: string, to: string, password: string): Promise<string>;
|
|
@@ -7,6 +10,4 @@ export interface Spec extends TurboModule {
|
|
|
7
10
|
zipFiles(files: string[], to: string): Promise<string>;
|
|
8
11
|
getUncompressedSize(path: string): Promise<number>;
|
|
9
12
|
}
|
|
10
|
-
|
|
11
|
-
export default _default;
|
|
12
|
-
//# sourceMappingURL=NativeZipArchive.d.ts.map
|
|
13
|
+
//# sourceMappingURL=ReactNativeZipArchive.nitro.d.ts.map
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ReactNativeZipArchive as ReactNativeZipArchiveType } from './ReactNativeZipArchive.nitro';
|
|
2
|
+
export declare const ZipArchive: ReactNativeZipArchiveType;
|
|
3
|
+
export declare const isPasswordProtected: (file: string) => Promise<boolean>;
|
|
4
|
+
export declare const unzip: (from: string, to: string) => Promise<string>;
|
|
5
|
+
export declare const unzipWithPassword: (from: string, to: string, password: string) => Promise<string>;
|
|
6
|
+
export declare const zipFolder: (from: string, to: string) => Promise<string>;
|
|
7
|
+
export declare const zipFiles: (files: string[], to: string) => Promise<string>;
|
|
8
|
+
export declare const getUncompressedSize: (path: string) => Promise<number>;
|
|
2
9
|
export declare const zip: (source: string, target: string) => Promise<string>;
|
|
3
|
-
export type
|
|
10
|
+
export type * from './ReactNativeZipArchive.nitro';
|
|
11
|
+
export type { ReactNativeZipArchive as ZipArchiveSpec } from './ReactNativeZipArchive.nitro';
|
|
4
12
|
//# sourceMappingURL=index.d.ts.map
|
package/nitro.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cxxNamespace": ["reactnativeziparchive"],
|
|
3
|
+
"ios": {
|
|
4
|
+
"iosModuleName": "ReactNativeZipArchive"
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"androidNamespace": ["reactnativeziparchive"],
|
|
8
|
+
"androidCxxLibName": "reactnativeziparchive"
|
|
9
|
+
},
|
|
10
|
+
"autolinking": {
|
|
11
|
+
"ReactNativeZipArchive": {
|
|
12
|
+
"swift": "ReactNativeZipArchive",
|
|
13
|
+
"kotlin": "ReactNativeZipArchive"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"ignorePaths": ["node_modules"]
|
|
17
|
+
}
|