[Gradle][MPP] zipUtils: Add ZipFile.copyPartially
^KT-48135 WIP
This commit is contained in:
committed by
Space
parent
2391720999
commit
74594c05ca
+6
-4
@@ -12,9 +12,12 @@ import java.util.zip.ZipOutputStream
|
|||||||
|
|
||||||
internal fun copyZipFilePartially(sourceZipFile: File, destinationZipFile: File, path: String) {
|
internal fun copyZipFilePartially(sourceZipFile: File, destinationZipFile: File, path: String) {
|
||||||
requireValidZipDirectoryPath(path)
|
requireValidZipDirectoryPath(path)
|
||||||
|
ZipFile(sourceZipFile).use { zip -> zip.copyPartially(destinationZipFile, path) }
|
||||||
|
}
|
||||||
|
|
||||||
ZipFile(sourceZipFile).use { zip ->
|
internal fun ZipFile.copyPartially(destinationZipFile: File, path: String) {
|
||||||
val entries = zip.listDescendants(path).toList()
|
requireValidZipDirectoryPath(path)
|
||||||
|
val entries = listDescendants(path).toList()
|
||||||
if (entries.isEmpty()) return
|
if (entries.isEmpty()) return
|
||||||
|
|
||||||
ZipOutputStream(destinationZipFile.outputStream()).use { destinationZipOutputStream ->
|
ZipOutputStream(destinationZipFile.outputStream()).use { destinationZipOutputStream ->
|
||||||
@@ -34,7 +37,7 @@ internal fun copyZipFilePartially(sourceZipFile: File, destinationZipFile: File,
|
|||||||
destinationZipOutputStream.putNextEntry(destinationEntry)
|
destinationZipOutputStream.putNextEntry(destinationEntry)
|
||||||
|
|
||||||
if (!sourceEntry.isDirectory) {
|
if (!sourceEntry.isDirectory) {
|
||||||
zip.getInputStream(sourceEntry).use { inputStream ->
|
getInputStream(sourceEntry).use { inputStream ->
|
||||||
inputStream.copyTo(destinationZipOutputStream)
|
inputStream.copyTo(destinationZipOutputStream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +45,6 @@ internal fun copyZipFilePartially(sourceZipFile: File, destinationZipFile: File,
|
|||||||
destinationZipOutputStream.closeEntry()
|
destinationZipOutputStream.closeEntry()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ZipFile.listDescendants(path: String): Sequence<ZipEntry> {
|
internal fun ZipFile.listDescendants(path: String): Sequence<ZipEntry> {
|
||||||
|
|||||||
Reference in New Issue
Block a user