Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] CompressBytes(byte[] data)
        {
            var o = new MemoryStream();
            var s = new ICSharpCode.SharpZipLib.Tar.TarOutputStream(o);

            s.Write(data, 0, data.Length);
            s.Close();
            o.Flush();
            o.Close();
            return(o.ToArray());
        }
Esempio n. 2
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();
            }
        }