Using NIO2 for writing zip file entries without corresponding folder entries
Rafael Winterhalter
rafael.wth at gmail.com
Wed Oct 10 12:00:10 UTC 2018
You are right with that it does emulate missing folders in the source file.
I have a use case where I patch a zip file with some additional entries
that are placed in directories of files that already exist in the zip file.
To do so, I have to add the directories for the added files. Doing so
confuses the processing backend which does not filter the folder entries
but treats them as normal files which causes this processor to crash when
treating them as regular files.
I understand that the file system abstraction mandates folders but for zip
files, I would find it practical if it was possible to write files without
demanding folders for them. The current work around is to write a whole new
file with ZipInputStream/ZipOutputStream and to copy all existing entries
what adds quite a bit of I/O overhead. Therefore, I would welcome the
mentioned feature.
Thanks for the explanation,
best regards, Rafael
Am Mi., 10. Okt. 2018 um 13:50 Uhr schrieb Alan Bateman <
Alan.Bateman at oracle.com>:
> On 10/10/2018 12:31, Rafael Winterhalter wrote:
> > Hi,
> >
> > I was wondering why the ZipFileSystem checked for the existence of a
> > file's parents before writing a file. Writing folder entries is not a
> > requirement in the specification for zip files and I find it strange
> > that the implementation enforces it. I found that even to be
> > problematic when altering a zip file where NIO2 requires you to add
> > folder entries that did not exist before.
> >
> If you using a zip file system to create a new zip file then it
> shouldn't be a surprise that you need to create a directory before
> creating entries in the directory. The zip file system is just trying to
> behave like a regular file system. The zip file system provider does
> lack a configuration option to strip directories when writing, that
> could potentially be added if important.
>
> One other thing is that the zip file system provider can open existing
> zip files that don't have entries for directories, it's should emulate
> them for that scenario.
>
> -Alan.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20181010/2a57bad2/attachment.html>
More information about the nio-dev
mailing list