Пример #1
0
        protected override void _Partir(string fichero, string sal1, string dir, long kb)
        {
            FileInfo fi = null;
            DirectoryInfo din = null;
            DirectoryInfo dout = new DirectoryInfo (dir);

            if (File.Exists (fichero)) {
                fi = new FileInfo (fichero);
            } else if (Directory.Exists (fichero)) {
                din = new DirectoryInfo (fichero);
            } else {
                throw new Exception ("" + fichero + " not found");
            }
            List<FileInfo> files = load (fichero);

            string baseName = "";
            if (fi != null) {
                baseName = fi.Name;
            } else if (din != null) {
                baseName = din.Name;
            }

            if ((sal1 == null) || (sal1 == string.Empty)) {
                //
                if (din != null) {
                    sal1 = din.Name;
                }
                if (fi != null) {
                    sal1 = fi.Name;
                }
            }

            long totalSize = calculateTotalSize (files);
            long fragments = totalSize / (kb * 1024);
            string s = "" + fragments;
            JoinInfo info = new JoinInfo ();
            info.OriginalFile = baseName;
            info.InitialFragment = 0;
            info.Digits = Math.Max (s.Length, 3);
            info.BaseName = sal1 + ".tar.gz.";
            info.Directory = dout;
            info.Length = totalSize;

            Stream stream = new SplitStream (info, kb * 1024, info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName + "sha512sum.dalle", "SHA512");
            stream = new GZipStream (stream, CompressionMode.Compress);
            TarOutputStream taros = new TarOutputStream (stream);
            foreach (FileInfo f in files) {

                TarEntry te = TarEntry.CreateEntryFromFile (f.FullName);
                te.UserId = 0;
                te.GroupId = 0;
                te.UserName = String.Empty;
                te.GroupName = String.Empty;
                taros.PutNextEntry (te);
                FileStream fs = f.OpenRead ();
                long leidosTotales = 0;
                byte[] buffer = new byte[Consts.BUFFER_LENGTH];
                int leidos = 0;
                while ((leidos = fs.Read (buffer, 0, buffer.Length)) > 0) {
                    taros.Write (buffer, 0, leidos);
                    leidosTotales += leidos;
                    OnProgress (leidosTotales, totalSize);
                }
                taros.CloseEntry ();
                fs.Close ();
            }
            taros.Close ();
            OnProgress (totalSize, totalSize);
        }
Пример #2
0
        /// <returns>El numero de fragmentos que se han creado.</returns>
        // TODO: Cambiar el orden de los parametros (String, st, long, int, int).
        protected override void _Partir(string fichero, string sal1, string dir, long kb)
        {
            if ((sal1 == null) || (sal1 == string.Empty))
            {
                sal1 = new FileInfo (fichero).Name;
            }
            JoinInfo info = new JoinInfo ();

            info.InitialFragment = 1;
            info.Digits = 3;
            info.OriginalFile = new FileInfo (fichero).Name;
            //info.BaseName = info.OriginalFile;
            info.BaseName = sal1 +".";
            info.Directory = new DirectoryInfo (dir);

            Stream stream = new SplitStream (
                info,
                kb * 1024,
                dir + Path.DirectorySeparatorChar + info.BaseName + "sha512sum",
                "SHA512");
            byte[] buffer = new byte[Consts.BUFFER_LENGTH];
            int leidos = 0;
            long transferidos = 0;
            long tamano = new FileInfo (fichero).Length;
            OnProgress (0, tamano);
            Stream fis = File.OpenRead (fichero);
            while ((leidos = fis.Read (buffer, 0, buffer.Length)) > 0) {
                stream.Write (buffer, 0, leidos);
                transferidos += leidos;
                OnProgress (transferidos, tamano);
            }
            fis.Close ();
            stream.Close ();

            //Partir (fichero, sal1, dir, kb, info);
        }