in intellij-plugin-structure/structure-base/src/main/kotlin/com/jetbrains/plugin/structure/base/decompress/Decompressor.kt [29:66]
fun extract(outputDir: Path) {
openStream()
try {
val actualSizeLimit = outputSizeLimit ?: Long.MAX_VALUE
var remainingSize = actualSizeLimit
loop@ while (true) {
val entry = nextEntry() ?: break
val outputFile = getEntryFile(outputDir, entry)
when (entry.type) {
Type.DIR -> {
outputFile.createDir()
}
Type.FILE -> {
val entryStream = nextEntryStream() ?: continue@loop
try {
val countingStream = BoundedInputStream.builder()
.setInputStream(entryStream)
.setMaxCount(remainingSize + 1)
.setPropagateClose(false)
.get()
outputFile.createParentDirs()
Files.copy(countingStream, outputFile)
remainingSize -= countingStream.count
if (remainingSize < 0) {
throw DecompressorSizeLimitExceededException(actualSizeLimit)
}
} finally {
closeNextEntryStream(entryStream)
}
}
Type.SYMLINK -> throw IOException("Symlinks are not allowed")
}
}
} finally {
closeStream()
}
}