コード例 #1
0
 /// <summary>
 /// Closes the specified directory entry.
 /// </summary>
 /// <param name="zip_entry">A directory entry previously opened with
 /// <see cref="zip_entry_open(ZipArchiveResource, ZipEntryResource, string)"/>.</param>
 /// <returns>Returns TRUE on success or FALSE on failure.</returns>
 public static bool zip_entry_close(ZipEntryResource zip_entry)
 {
     if (zip_entry != null)
     {
         zip_entry.Dispose();
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
        /// <summary>
        /// Reads from an open directory entry.
        /// </summary>
        /// <param name="zip_entry">A directory entry returned by <see cref="zip_read(ZipArchiveResource)"/>.</param>
        /// <param name="length">The number of bytes to return.</param>
        /// <returns>Returns the data read, empty string or NULL on end of a file and on error.</returns>
        public static PhpValue zip_entry_read(ZipEntryResource zip_entry, int length = 1024)
        {
            // Although according to the PHP documentation error codes should be retrieved,
            // it returns empty strings or NULL instead
            if (zip_entry == null)
            {
                PhpException.ArgumentNull(nameof(zip_entry));
                return(PhpValue.Null);
            }

            if (zip_entry == null || !zip_entry.IsValid || zip_entry.DataStream == null)
            {
                PhpException.InvalidArgument(nameof(zip_entry));
                return(PhpValue.Create(new PhpString(string.Empty)));
            }

            if (length <= 0)
            {
                PhpException.InvalidArgument(nameof(length));
                return(PhpValue.Create(new PhpString(string.Empty)));
            }

            try
            {
                var buffer = new byte[length];
                int read   = zip_entry.DataStream.Read(buffer, 0, length);

                if (read != length)
                {
                    Array.Resize(ref buffer, read);
                }

                return(PhpValue.Create(new PhpString(buffer)));
            }
            catch (Exception e)
            {
                PhpException.Throw(PhpError.Warning, e.Message);
                return(PhpValue.Create(new PhpString(string.Empty)));
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
 /// <summary>
 /// Returns the compression method of the specified directory entry.
 /// </summary>
 /// <remarks>
 /// Currently not supported.
 /// </remarks>
 /// <param name="zip_entry">A directory entry returned by <see cref="zip_read(ZipArchiveResource)"/>.</param>
 /// <returns>The compression method.</returns>
 public static string zip_entry_compressionmethod(ZipEntryResource zip_entry)
 {
     // TODO: Implement using reflection or by moving the code of ZipArchive here)
     PhpException.FunctionNotSupported(nameof(zip_entry_compressionmethod));
     return(string.Empty);
 }
コード例 #5
0
 /// <summary>
 /// Returns the compressed size of the specified directory entry.
 /// </summary>
 /// <param name="zip_entry">A directory entry returned by <see cref="zip_read(ZipArchiveResource)"/>.</param>
 /// <returns>The compressed size.</returns>
 public static long zip_entry_compressedsize(ZipEntryResource zip_entry) => zip_entry.Entry.CompressedLength;
コード例 #6
0
 /// <summary>
 /// Returns the actual size of the specified directory entry.
 /// </summary>
 /// <param name="zip_entry">A directory entry returned by <see cref="zip_read"/>.</param>
 /// <returns>The size of the directory entry.</returns>
 public static long zip_entry_filesize(ZipEntryResource zip_entry) => zip_entry.Entry.Length;
コード例 #7
0
 /// <summary>
 /// Returns the name of the specified directory entry.
 /// </summary>
 /// <param name="zip_entry">A directory entry returned by <see cref="zip_read"/>.</param>
 /// <returns>The name of the directory entry.</returns>
 public static string zip_entry_name(ZipEntryResource zip_entry) => zip_entry.Entry.FullName;