korlibs-archive / korio

Korio: Kotlin cORoutines I/O : Virtual File System + Async/Sync Streams + Async TCP Client/Server + WebSockets for Multiplatform Kotlin 1.3
https://korlibs.soywiz.com/korio/
MIT License
361 stars 34 forks source link

Can't open a zip directory for READ. #135

Closed Kesanov closed 3 years ago

Kesanov commented 3 years ago

Unzipping nested folders will throw an exception Can't open a zip directory for READ. The unzip code is following:

ZipVfs(file).listRecursive{ true }.collect {
    it.copyTo(dir[it.path])
}

The issue causing that problem is the line if (entry.isDirectory) throw IOException("Can't open a zip directory for $mode"). Is that on purpose? Shouldn't it be TODO instead?

soywiz commented 3 years ago

I guess that's correct. You can only open files for reading, not directories. What's the content as bytes of a directory? It doesn't make sense to open it. The problem is probably related to either if listRecursive should filter by default directories. Not sure what other implementations do right now, but this one might be returning both files and directories. And that means that if you want to copy, you must filter directories. Either by listRecursive { it.isFile } or listRecrusive { !it.isDirectory }, or listRecursive().collect { if (!it.isDirectory) it.copyTo(dir[it.path]) }

Kesanov commented 3 years ago

Hm, I thought that listRecursive indeed lists only files and not folders. My mistake.