List Archive

Thread

Thread Index

Message

From: Thomas Klausner <tk%giga.or.at@localhost>
To: Qifei Wang <qfwang%google.com@localhost>
Subject: Re: Failed to unzip file by zip_fdopen with the error code ZIP_ER_OPNOTSUPP
Date: Sun, 8 Sep 2019 09:10:35 +0200

Hi again!

On Sat, Sep 07, 2019 at 06:09:17PM -0700, Qifei Wang wrote:
>   Thanks for your reply. I figured out the problem was SEEK
> <https://github.com/nih-at/libzip/blob/master/lib/zip_source_filep.c#L188> (
> https://github.com/nih-at/libzip/blob/master/lib/zip_source_filep.c#L188)
> is not added as the supported operator for the zip file opened from the
> file descriptor. That is because the file sb.st_mode (
> https://github.com/nih-at/libzip/blob/master/lib/zip_source_filep.c#L187)
> is not recognized as a regular file. That might be caused since the file
> descriptor is obtained from a content URI on Android.

That sounds like a reasonable analysis.

>   To open a zip archive from a memory buffer, should I use zip_source_buffer
> or zip_source_buffer_create methods?

Yes. There is a complete example for handling an in-memory zip archive
in examples/in-memory.c.

Cheers,
 Thomas


> Cheers,
> 
> Qifei Wang
> 
> 
> On Sat, Sep 7, 2019 at 1:52 PM Thomas Klausner <tk%giga.or.at@localhost> 
> wrote:
> 
> > On Fri, Sep 06, 2019 at 06:03:06PM -0700, Qifei Wang wrote:
> > >   I am trying to unzip a zip file from file descriptor by the following
> > > code snippet. It reports the error ZIP_ER_OPNOTSUPP. The file descriptor
> > is
> > > valid. The error seems reported by zip_open_from_source() method. See
> > > https://github.com/nih-at/libzip/blob/master/lib/zip_open.c#L106. Any
> > idea
> > > about this?
> >
> > I see one location that actually does set that error:
> >
> >     if ((st.valid & ZIP_STAT_SIZE) == 0) {
> >         zip_error_set(error, ZIP_ER_SEEK, EOPNOTSUPP);
> >         return NULL;
> >     }
> >
> > For reading an archive, libzip starts at the end and parses the
> > EOCD(64) marker and then the central directory. Perhaps the stat() to
> > find out the filesize failed?
> >
> > You could read the file from the server into a memory buffer and open
> > the zip archive from there.
> >  Thomas
> >

Made by MHonArc.