예제 #1
0
        private void _Check_ZIP(string pathFileZip, IDTSComponentEvents componentEvents)
        {
            bool b = false;

            if (_testarchive)
            {
                using (ICSharpCode.SharpZipLib.Zip.ZipInputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(pathFileZip)))
                {
                    if (!string.IsNullOrEmpty(_password))
                    {
                        fz.Password = _password;
                    }

                    try
                    {
                        ICSharpCode.SharpZipLib.Zip.ZipEntry ze = fz.GetNextEntry();
                        componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _folderSource + _fileZip + ")", null, 0, ref b);

                        while (ze != null)
                        {
                            componentEvents.FireInformation(1, "UnZip SSIS", "Verifying Entry: " + ze.Name, null, 0, ref b);

                            fz.CopyTo(System.IO.MemoryStream.Null);
                            fz.Flush();

                            fz.CloseEntry();
                            ze = fz.GetNextEntry();
                        }
                        componentEvents.FireInformation(1, "UnZip SSIS", "File ZIP verified ZIP (" + _folderSource + _fileZip + ")", null, 0, ref b);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Verify file: " + _fileZip + " failed. (" + ex.Message + ")");
                    }
                    finally
                    {
                        fz.Close();
                    }
                }
            }
        }
예제 #2
0
        /// <summary> 解压数据 </summary>
        public static byte[] Decompress(Stream source)
        {
#if false//SCORPIO_UWP && !UNITY_EDITOR
            using (MemoryStream stream = new MemoryStream()) {
                System.IO.Compression.ZipArchive      zipStream = new System.IO.Compression.ZipArchive(source, System.IO.Compression.ZipArchiveMode.Read);
                System.IO.Compression.ZipArchiveEntry zipEntry  = zipStream.Entries[0];
                Stream entryStream = zipEntry.Open();
                int    count       = 0;
                byte[] data        = new byte[4096];
                while ((count = entryStream.Read(data, 0, data.Length)) != 0)
                {
                    stream.Write(data, 0, count);
                }
                zipStream.Dispose();
                byte[] ret = stream.ToArray();
                stream.Dispose();
                return(ret);
            }
#else
            using (MemoryStream stream = new MemoryStream()) {
                ICSharpCode.SharpZipLib.Zip.ZipInputStream zipStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(source);
                zipStream.GetNextEntry();
                int    count = 0;
                byte[] data  = new byte[4096];
                while ((count = zipStream.Read(data, 0, data.Length)) != 0)
                {
                    stream.Write(data, 0, count);
                }
                zipStream.Flush();
                byte[] ret = stream.ToArray();
                zipStream.Dispose();
                stream.Dispose();
                return(ret);
            }
#endif
        }