Esempio n. 1
0
        /// <summary>
        /// Reads the next entry in a zip file archive.
        /// </summary>
        /// <param name="zip">A ZIP file previously opened with <see cref="zip_open(Context, string)"/>.</param>
        /// <returns>Returns a directory entry resource for later use with the zip_entry_... functions, or FALSE
        /// if there are no more entries to read, or an error code if an error occurred.</returns>
        public static PhpValue zip_read(ZipArchiveResource zip)
        {
            if (zip == null || !zip.IsValid)
            {
                PhpException.InvalidArgument(nameof(zip));
                return(false);
            }

            try
            {
                if (zip.Enumerator.MoveNext())
                {
                    return(PhpValue.FromClass(new ZipEntryResource(zip.Enumerator.Current)));
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                PhpException.Throw(PhpError.Warning, e.Message);
                return(ER_INTERNAL);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Opens a directory entry in a zip file for reading.
        /// </summary>
        /// <param name="zip">A valid resource handle returned by <see cref="zip_open(Context, string)"/>.</param>
        /// <param name="zip_entry">A directory entry returned by <see cref="zip_read(ZipArchiveResource)"/>.</param>
        /// <param name="mode">Ignored, only binary read is supported.</param>
        /// <returns>Returns TRUE on success or FALSE on failure.</returns>
        public static bool zip_entry_open(ZipArchiveResource zip, ZipEntryResource zip_entry, string mode = "rb")
        {
            if (zip_entry == null || !zip_entry.IsValid)
            {
                PhpException.InvalidArgument(nameof(zip_entry));
                return(false);
            }

            if (zip_entry.DataStream != null)
            {
                return(true);
            }

            try
            {
                zip_entry.DataStream = zip_entry.Entry.Open();
                return(true);
            }
            catch (Exception e)
            {
                PhpException.Throw(PhpError.Warning, e.Message);
                return(false);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Closes the given ZIP file archive.
 /// </summary>
 /// <param name="zip">A ZIP file previously opened with <see cref="zip_open(Context, string)"/>.</param>
 public static void zip_close(ZipArchiveResource zip) => zip?.Dispose();