korlibs-archive / korio

Korio: Kotlin cORoutines I/O : Virtual File System + Async/Sync Streams + Async TCP Client/Server + WebSockets for Multiplatform Kotlin 1.3

Home Page:https://korlibs.soywiz.com/korio/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't open a zip directory for READ.

Kesanov opened this issue · comments

commented

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?

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]) }

commented

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