react-native-kookit 0.2.8 → 0.2.9
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.
|
@@ -87,7 +87,7 @@ class SmbClient {
|
|
|
87
87
|
|
|
88
88
|
suspend fun list(path: String?): List<SmbFileInfo> = withContext(Dispatchers.IO) {
|
|
89
89
|
val disk = requireShare()
|
|
90
|
-
|
|
90
|
+
val dirPath = (path?.trim()?.ifEmpty { null } ?: "").replace('\\', '/').removePrefix("./")
|
|
91
91
|
val results = mutableListOf<SmbFileInfo>()
|
|
92
92
|
for (info in disk.list(dirPath)) {
|
|
93
93
|
val name = info.fileName
|
|
@@ -102,11 +102,20 @@ class SmbClient {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
suspend fun download(remotePath: String, localPath: String, onProgress: ((Long, Long) -> Unit)? = null) = withContext(Dispatchers.IO) {
|
|
105
|
-
|
|
105
|
+
val disk = requireShare()
|
|
106
|
+
val normRemote = remotePath.replace('\\', '/').removePrefix("./")
|
|
106
107
|
java.io.File(localPath).parentFile?.mkdirs()
|
|
108
|
+
// Request read data + attributes to allow QueryInfo; some servers require READ_ATTRIBUTES for size query
|
|
109
|
+
val readAccess = setOf(
|
|
110
|
+
AccessMask.FILE_READ_DATA,
|
|
111
|
+
AccessMask.FILE_READ_ATTRIBUTES,
|
|
112
|
+
AccessMask.FILE_READ_EA,
|
|
113
|
+
AccessMask.READ_CONTROL,
|
|
114
|
+
AccessMask.SYNCHRONIZE
|
|
115
|
+
)
|
|
107
116
|
disk.openFile(
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
normRemote,
|
|
118
|
+
readAccess,
|
|
110
119
|
setOf(FileAttributes.FILE_ATTRIBUTE_NORMAL),
|
|
111
120
|
SMB2ShareAccess.ALL,
|
|
112
121
|
SMB2CreateDisposition.FILE_OPEN,
|
|
@@ -116,13 +125,19 @@ class SmbClient {
|
|
|
116
125
|
val buffer = ByteArray(8192)
|
|
117
126
|
var total = 0L
|
|
118
127
|
var read: Int
|
|
119
|
-
|
|
128
|
+
// Some servers deny QueryInfo on the handle unless READ_ATTRIBUTES is requested.
|
|
129
|
+
// Guard this to allow download to proceed even when size is unavailable.
|
|
130
|
+
val fileSize = try {
|
|
131
|
+
f.fileInformation.standardInformation.endOfFile
|
|
132
|
+
} catch (_: Exception) {
|
|
133
|
+
-1L
|
|
134
|
+
}
|
|
120
135
|
while (true) {
|
|
121
136
|
read = f.read(buffer, total)
|
|
122
137
|
if (read <= 0) break
|
|
123
138
|
out.write(buffer, 0, read)
|
|
124
139
|
total += read
|
|
125
|
-
onProgress?.invoke(total, fileSize)
|
|
140
|
+
onProgress?.invoke(total, if (fileSize > 0) fileSize else 0L)
|
|
126
141
|
}
|
|
127
142
|
out.flush()
|
|
128
143
|
}
|
|
@@ -131,12 +146,20 @@ class SmbClient {
|
|
|
131
146
|
|
|
132
147
|
suspend fun upload(localPath: String, remotePath: String, onProgress: ((Long, Long) -> Unit)? = null) = withContext(Dispatchers.IO) {
|
|
133
148
|
val disk = requireShare()
|
|
149
|
+
val normRemote = remotePath.replace('\\', '/').removePrefix("./")
|
|
134
150
|
val file = java.io.File(localPath)
|
|
135
151
|
val size = file.length()
|
|
136
152
|
file.inputStream().use { input ->
|
|
153
|
+
val writeAccess = setOf(
|
|
154
|
+
AccessMask.FILE_WRITE_DATA,
|
|
155
|
+
AccessMask.FILE_WRITE_ATTRIBUTES,
|
|
156
|
+
AccessMask.FILE_WRITE_EA,
|
|
157
|
+
AccessMask.READ_CONTROL,
|
|
158
|
+
AccessMask.SYNCHRONIZE
|
|
159
|
+
)
|
|
137
160
|
disk.openFile(
|
|
138
|
-
|
|
139
|
-
|
|
161
|
+
normRemote,
|
|
162
|
+
writeAccess,
|
|
140
163
|
setOf(FileAttributes.FILE_ATTRIBUTE_NORMAL),
|
|
141
164
|
SMB2ShareAccess.ALL,
|
|
142
165
|
SMB2CreateDisposition.FILE_OVERWRITE_IF,
|
|
@@ -156,17 +179,19 @@ class SmbClient {
|
|
|
156
179
|
|
|
157
180
|
suspend fun delete(path: String, isDirectory: Boolean = false) = withContext(Dispatchers.IO) {
|
|
158
181
|
val disk = requireShare()
|
|
182
|
+
val norm = path.replace('\\', '/').removePrefix("./")
|
|
159
183
|
if (isDirectory) {
|
|
160
|
-
disk.rmdir(
|
|
184
|
+
disk.rmdir(norm, false)
|
|
161
185
|
} else {
|
|
162
|
-
disk.rm(
|
|
186
|
+
disk.rm(norm)
|
|
163
187
|
}
|
|
164
188
|
}
|
|
165
189
|
|
|
166
190
|
suspend fun mkdir(path: String) = withContext(Dispatchers.IO) {
|
|
167
191
|
val disk = requireShare()
|
|
168
|
-
|
|
169
|
-
|
|
192
|
+
val norm = path.replace('\\', '/').removePrefix("./")
|
|
193
|
+
if (!disk.folderExists(norm)) {
|
|
194
|
+
disk.mkdir(norm)
|
|
170
195
|
}
|
|
171
196
|
}
|
|
172
197
|
}
|
package/package.json
CHANGED