예제 #1
0
 /// <summary>
 /// Creates a new wrapper around a tar file entry.
 /// </summary>
 /// <param name="baseEntry"></param>
 public TarEntry(ICSharpCode.SharpZipLib.Tar.TarEntry baseEntry)
 {
     this.baseEntry = baseEntry;
 }
예제 #2
0
        private void _DeCompressTAR(string pathFileTAR, IDTSComponentEvents componentEvents, System.IO.Stream stream)
        {
            bool b = false;

            if (stream == null)
            {
                stream = System.IO.File.OpenRead(pathFileTAR);
            }

            using (ICSharpCode.SharpZipLib.Tar.TarInputStream tar = new ICSharpCode.SharpZipLib.Tar.TarInputStream(stream))
            {
                ICSharpCode.SharpZipLib.Tar.TarEntry te = tar.GetNextEntry();

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

                    if ((!System.Text.RegularExpressions.Regex.Match(fn, _fileFilter).Success) || (te.IsDirectory && te.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)
                        }

                        te = tar.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))
                    {
                        tar.CopyTo(fs);
                        fs.Flush();
                    }

                    te = tar.GetNextEntry();
                }

                tar.Flush();
                tar.Close();
            }
        }
예제 #3
0
        private void _CompressTAR(string pathFileTAR, IDTSComponentEvents componentEvents, System.IO.Stream stream)
        {
            bool b = false;

            System.IO.DirectoryInfo di   = new System.IO.DirectoryInfo(_folderSource);
            System.IO.FileInfo[]    fi_s = di.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

            if (stream == null)
            {
                stream = System.IO.File.Create(pathFileTAR);
            }

            using (ICSharpCode.SharpZipLib.Tar.TarOutputStream tar = new ICSharpCode.SharpZipLib.Tar.TarOutputStream(stream))
            {
                foreach (System.IO.FileInfo fi in fi_s)
                {
                    if (!System.Text.RegularExpressions.Regex.Match(fi.FullName, _fileFilter).Success)
                    {
                        componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": file " + fi.FullName + " doesn't match regex filter '" + _fileFilter + "'. File not processed.", null, 0, ref b);
                        continue;
                    }

                    componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": Compress (with '" + _storePaths.ToString() + "') file: " + fi.FullName, null, 0, ref b);
                    string fileName = fi.FullName;

                    if (_storePaths == Store_Paths.Absolute_Paths)
                    {
                        //Absolute Path
                        fileName = fi.FullName.Replace("\\", "/").Substring(3);
                    }
                    else if (_storePaths == Store_Paths.Relative_Paths)
                    {
                        //Relative Path
                        fileName = fileName.Replace(_folderSource, "").Replace("\\", "/");
                        if (_addRootFolder)
                        {
                            fileName = (di.Name + "/" + fileName).Replace("//", "/");
                        }
                    }
                    else if (_storePaths == Store_Paths.No_Paths)
                    {
                        //No Path
                        fileName = fi.Name;
                    }
                    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.Open, System.IO.FileAccess.Read))
                    {
                        ICSharpCode.SharpZipLib.Tar.TarEntry te = ICSharpCode.SharpZipLib.Tar.TarEntry.CreateTarEntry(fileName);
                        te.Size = fs.Length;
                        tar.PutNextEntry(te);

                        fs.CopyTo(tar);

                        fs.Flush();
                        tar.Flush();

                        tar.CloseEntry();
                    }
                }

                tar.Flush();
                tar.Close();
            }
        }
예제 #4
0
 /// <summary>
 /// Creates a new wrapper around a tar file entry.
 /// </summary>
 /// <param name="baseEntry"></param>
 public TarEntry(ICSharpCode.SharpZipLib.Tar.TarEntry baseEntry)
 {
     this.baseEntry = baseEntry;
 }