/// <summary>
        /// Decompresses the given data stream from its source ZIP or GZIP format.
        /// </summary>
        /// <param name="dataBytes"></param>
        /// <returns></returns>
        private static byte[] Inflate(byte[] dataBytes)
        {
            byte[] outputBytes    = null;
            var    zipInputStream =
                new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new MemoryStream(dataBytes));

            if (zipInputStream.CanDecompressEntry)
            {
                MemoryStream zipoutStream = new MemoryStream();
#if XBOX
                byte[] buf = new byte[4096];
                int    amt = -1;
                while (true)
                {
                    amt = zipInputStream.Read(buf, 0, buf.Length);
                    if (amt == -1)
                    {
                        break;
                    }
                    zipoutStream.Write(buf, 0, amt);
                }
#else
                zipInputStream.CopyTo(zipoutStream);
#endif
                outputBytes = zipoutStream.ToArray();
            }
            else
            {
                try {
                    var gzipInputStream =
                        new ICSharpCode.SharpZipLib.GZip.GZipInputStream(new MemoryStream(dataBytes));


                    MemoryStream zipoutStream = new MemoryStream();

#if XBOX
                    byte[] buf = new byte[4096];
                    int    amt = -1;
                    while (true)
                    {
                        amt = gzipInputStream.Read(buf, 0, buf.Length);
                        if (amt == -1)
                        {
                            break;
                        }
                        zipoutStream.Write(buf, 0, amt);
                    }
#else
                    gzipInputStream.CopyTo(zipoutStream);
#endif
                    outputBytes = zipoutStream.ToArray();
                }
                catch (Exception exc)
                {
                    CCLog.Log("Error decompressing image data: " + exc.Message);
                }
            }

            return(outputBytes);
        }
示例#2
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();
                    }
                }
            }
        }
示例#3
0
 static void TestZipArchive(string filename)
 {
     Console.WriteLine("testing zip archive " + filename);
     try
     {
         using (var file = File.OpenRead(filename))
             using (var stream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(file))
             {
                 for (var entry = stream.GetNextEntry(); entry != null; entry = stream.GetNextEntry())
                 {
                     Console.WriteLine(entry.Name + ":");
                     stream.CopyTo(Console.OpenStandardOutput());
                     Console.WriteLine("");
                 }
             }
     }
     catch (Exception e)
     {
         Console.Write(e.Message + e.StackTrace);
     }
 }
示例#4
0
        private void _DeCompressZIP(string pathFileZip, IDTSComponentEvents componentEvents)
        {
            bool b = false;

            _Check_ZIP(pathFileZip, componentEvents);

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

                ICSharpCode.SharpZipLib.Zip.ZipEntry ze = fz.GetNextEntry();

                while (ze != null)
                {
                    string             fn = ze.Name.Replace("/", "\\");
                    System.IO.FileInfo fi = null;

                    if ((!System.Text.RegularExpressions.Regex.Match(fn, _fileFilter).Success) || (ze.IsDirectory && ze.Size == 0))
                    {
                        if (!System.Text.RegularExpressions.Regex.Match(fn, _fileFilter).Success)
                        {
                            componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": file " + fn + " doesn't match regex filter '" + _fileFilter + "'", null, 0, ref b); //  Added information display when regex doesn't match (Updated on 2015-12-30 by Nico_FR75)
                        }

                        fz.CloseEntry();
                        ze = fz.GetNextEntry();
                        continue;
                    }

                    componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": De-Compress (with '" + _storePaths.ToString() + "') file: " + fn, null, 0, ref b);

                    if (_storePaths == Store_Paths.Absolute_Paths || _storePaths == Store_Paths.Relative_Paths)
                    {
                        //Absolute / Relative Path
                        fi = new System.IO.FileInfo(_folderDest + fn);
                        if (!System.IO.Directory.Exists(fi.DirectoryName))
                        {
                            System.IO.Directory.CreateDirectory(fi.DirectoryName);
                        }
                    }
                    else if (_storePaths == Store_Paths.No_Paths)
                    {
                        //No Path
                        fi = new System.IO.FileInfo(_folderDest + System.IO.Path.GetFileName(fn));
                    }
                    else
                    {
                        throw new Exception("Please select type Store Paths (No_Paths / Relative_Paths / Absolute_Paths).");
                    }

                    using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        fz.CopyTo(fs);
                        fs.Flush();
                    }

                    fz.CloseEntry();
                    ze = fz.GetNextEntry();
                }

                fz.Close();
            }
        }
示例#5
0
        /// <summary>
        /// Decompresses the given data stream from its source ZIP or GZIP format.
        /// </summary>
        /// <param name="dataBytes"></param>
        /// <returns></returns>
        private static byte[] Inflate(byte[] dataBytes)
        {
            byte[] outputBytes = null;
            var zipInputStream =
                new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new MemoryStream(dataBytes));

            if (zipInputStream.CanDecompressEntry) {

                MemoryStream zipoutStream = new MemoryStream();
            #if XBOX
                byte[] buf = new byte[4096];
                int amt = -1;
                while (true)
                {
                    amt = zipInputStream.Read(buf, 0, buf.Length);
                    if (amt == -1)
                    {
                        break;
                    }
                    zipoutStream.Write(buf, 0, amt);
                }
            #else
                zipInputStream.CopyTo(zipoutStream);
            #endif
                outputBytes = zipoutStream.ToArray();
            }
            else {

                try {
                var gzipInputStream =
                    new ICSharpCode.SharpZipLib.GZip.GZipInputStream(new MemoryStream(dataBytes));

                MemoryStream zipoutStream = new MemoryStream();

            #if XBOX
                byte[] buf = new byte[4096];
                int amt = -1;
                while (true)
                {
                    amt = gzipInputStream.Read(buf, 0, buf.Length);
                    if (amt == -1)
                    {
                        break;
                    }
                    zipoutStream.Write(buf, 0, amt);
                }
            #else
                gzipInputStream.CopyTo(zipoutStream);
            #endif
                outputBytes = zipoutStream.ToArray();
                }
                catch (Exception exc)
                {
                    CCLog.Log("Error decompressing image data: " + exc.Message);
                }

            }

            return outputBytes;
        }
示例#6
0
        /// <summary>
        /// Decompresses the given data stream from its source ZIP or GZIP format.
        /// </summary>
        /// <param name="dataBytes"></param>
        /// <returns></returns>
        private static byte[] Inflate(byte[] dataBytes)
        {
            byte[] outputBytes = null;
            var zipInputStream =
                new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new MemoryStream(dataBytes));

            if (zipInputStream.CanDecompressEntry) {

                MemoryStream zipoutStream = new MemoryStream();

                zipInputStream.CopyTo(zipoutStream);
                outputBytes = zipoutStream.ToArray();
            }
            else {

                try {
                var gzipInputStream =
                    new ICSharpCode.SharpZipLib.GZip.GZipInputStream(new MemoryStream(dataBytes));

                MemoryStream zipoutStream = new MemoryStream();

                gzipInputStream.CopyTo(zipoutStream);
                outputBytes = zipoutStream.ToArray();
                }
                catch (Exception exc)
                {
                    CCLog.Log("Error decompressing image data: " + exc.Message);
                }

            }

            return outputBytes;
        }