Skip to content

Commit

Permalink
fix: import config (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang authored May 23, 2023
1 parent 6816df9 commit 507c744
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion cosky-rest-api/src/main/kotlin/me/ahoo/cosky/rest/util/Zips.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.nio.charset.StandardCharsets
import java.nio.file.Paths
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
import java.util.zip.ZipOutputStream
import kotlin.io.path.isHidden
import kotlin.io.path.name

/**
* Zip tool.
Expand All @@ -45,22 +48,30 @@ object Zips {
return unzip(ByteArrayInputStream(zipSource))
}

@Suppress("LoopWithTooManyJumpStatements")
@JvmStatic
fun unzip(zipSource: InputStream): List<ZipItem> {
val items: MutableList<ZipItem> = ArrayList()
ZipInputStream(zipSource).use { zipInputStream ->
var entry: ZipEntry? = zipInputStream.nextEntry
while (entry != null) {
if (entry.isDirectory) {
entry = zipInputStream.nextEntry
continue
}
val path = Paths.get(entry.name)
if (path.isHidden()) {
entry = zipInputStream.nextEntry
continue
}

ByteArrayOutputStream().use { itemOutputStream ->
val buffer = ByteArray(1024)
var offset: Int
while (zipInputStream.read(buffer).also { offset = it } != -1) {
itemOutputStream.write(buffer, 0, offset)
}
val entryName = entry!!.name
val entryName = path.fileName.name
items.add(ZipItem.of(entryName, itemOutputStream.toString("UTF-8")))
}
entry = zipInputStream.nextEntry
Expand All @@ -77,5 +88,11 @@ object Zips {
return ZipItem(name, data)
}
}

override fun toString(): String {
return "ZipItem(name='$name')"
}


}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# limitations under the License.
#
group=me.ahoo.cosky
version=3.3.13
version=3.3.14
description=High-performance, low-cost microservice governance platform. Service Discovery and Configuration Service.
website=https://github.com/Ahoo-Wang/cosky
issues=https://github.com/Ahoo-Wang/cosky/issues
Expand Down

0 comments on commit 507c744

Please sign in to comment.