Exemplo n.º 1
0
        public void Comprimir()
        {
            string directorio;

            directorio = root + @"\\Upload\\";
            if (!Directory.Exists(directorio + "\\Compresion\\"))
            {
                DirectoryInfo di = Directory.CreateDirectory(directorio + "\\Compresion\\");
            }
            List <int> comprimido = new List <int>();
            string     text       = System.IO.File.ReadAllText(@path);

            comprimido = LZW.Compresion(text);
            List <char> bytecompress = new List <char>();

            foreach (int numero in comprimido)
            {
                bytecompress.Add((char)numero);
            }
            NombreTemporal = NombreTemporal.Replace(".txt", "");
            root           = root + @"\\Upload\\Compresion\\" + NombreTemporal + "compresion" + ".lzw";

            using (StreamWriter outputFile = new StreamWriter(root))
            {
                foreach (char caracter in bytecompress)
                {
                    outputFile.Write(caracter.ToString());
                }
            }
        }
Exemplo n.º 2
0
        public string Post(IFormFile file, string name)
        {
            LZW.Compresion(file, name);
            var NewFile = new FileInfo(Path.Combine(Environment.CurrentDirectory, "Compressions", $"{name}.lzw"));

            CompressionsCollections.EscrituraCompresiones(
                new CompressionsCollections
            {
                Nombre_Del_Archivo_Original   = file.FileName,
                Nombre_Del_Archivo_Comprimido = $"{name}.lzw",
                Ruta_Del_Archivo_Comprimido   = Path.Combine(Environment.CurrentDirectory, "Compressions", $"{name}.lzw"),
                Razon_De_Compresion           = (double)NewFile.Length / (double)file.Length,
                Factor_De_Compresion          = (double)file.Length / (double)NewFile.Length,
                Porcentaje = 100 - (((double)NewFile.Length / (double)file.Length) * 100)     // correccion del anterior (lab03), se muestra el porcentaje de reduccion real
            });
            return("Archivo Compreso en :" + NewFile.ToString());
        }
Exemplo n.º 3
0
        public static string CompressFile(string filePath, string filename, string name)
        {
            LZW          Compresor_lzw  = new LZW();
            FileStream   fileC          = new FileStream(filePath, FileMode.OpenOrCreate);
            BinaryReader Lector         = new BinaryReader(fileC);
            int          Cant_Byte_Read = 10000;
            int          Aumentar_Max   = 1;

            byte[] Text = new byte[Cant_Byte_Read];
            Text = Lector.ReadBytes(Cant_Byte_Read);
            while (fileC.Position < fileC.Length)
            {
                byte[] Aux = Lector.ReadBytes(Cant_Byte_Read);
                Array.Resize(ref Text, Text.Length + Aux.Length);
                Aux.CopyTo(Text, Cant_Byte_Read * Aumentar_Max);
                Aumentar_Max++;
            }
            Lector.Close();
            byte[] Impresor = Compresor_lzw.Compresion(Text);
            byte[] Result   = new byte[filename.Length + 1];
            Result[0] = Convert.ToByte(filename.Length);
            for (int i = 1; i <= filename.Length; i++)
            {
                Result[i] = Convert.ToByte(Convert.ToChar(filename[i - 1]));
            }
            Array.Resize(ref Result, filename.Length + 1 + Impresor.Length);
            Impresor.CopyTo(Result, filename.Length + 1);
            string FinalFileName = Directory.GetCurrentDirectory() + "\\Compressed\\" + name + ".lzw";
            int    count         = 0;

            while (File.Exists(FinalFileName))
            {
                count++;
                FinalFileName = Directory.GetCurrentDirectory() + "\\Compressed\\" + name + count + ".lzw";
            }
            FileStream   archivo  = new FileStream(FinalFileName, FileMode.OpenOrCreate);
            BinaryWriter Escritor = new BinaryWriter(archivo);

            Escritor.Write(Result);
            Escritor.Close();
            double[] data = Compresor_lzw.Datos_Compresion();
            Compression.WriteRegistry(filename, FinalFileName, data[0], data[1], data[2]);
            File.Delete(filePath);
            return(FinalFileName);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            LZW CompresorLZW = new LZW();

            Header();
            TitleOption1();
            bool exit = false;

            while (!exit)
            {
                try
                {
                    Header();
                    TitleOption1();
                    Console.ForegroundColor = ConsoleColor.Yellow;

                    Console.WriteLine("Ingrese el texto a comprimir:\n\n");
                    Console.ResetColor();
                    string Text = Console.ReadLine();
                    if (String.IsNullOrEmpty(Text))
                    {
                        throw new FormatException();
                    }
                    byte[] texto = new byte[Text.Length];
                    for (int i = 0; i < Text.Length; i++)
                    {
                        texto[i] = Convert.ToByte(Convert.ToChar(Text[i]));
                    }
                    byte[] Comprimido = CompresorLZW.Compresion(texto);
                    string result     = "";
                    foreach (byte bit in Comprimido)
                    {
                        result += Convert.ToString(Convert.ToChar(bit));
                    }
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("\n\nEl texto comprimido es el siguiente:\n\n");
                    Console.ResetColor();
                    Console.WriteLine(result);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("\n\nPresione cualquier tecla para ver el mismo texto descompreso.");
                    Console.ResetColor();
                    Console.ReadKey();
                    Console.Clear();
                    Header();
                    TitleOption2();
                    result = "";
                    byte[] Descomprimido = CompresorLZW.Descompresion(Comprimido);
                    foreach (byte bit in Descomprimido)
                    {
                        result += Convert.ToString(Convert.ToChar(bit));
                    }
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("\n\nEl texto descomprimido es el siguiente:");
                    Console.ResetColor();
                    Console.WriteLine("\n" + result + "\n\n");
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Proceso finalizado. Presione una tecla.");
                    Console.ResetColor();
                    Console.ReadKey();
                    Header();
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    string e = "Ingrese S para volver a comprimir o cualquier cosa para salir del programa.";
                    Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (e.Length / 2)) + "}", e) + "\n");
                    Console.ResetColor();
                    if (!Convert.ToString(Console.ReadLine()).Equals("S"))
                    {
                        exit = true;
                    }
                }
                catch
                {
                    Header();
                    string e = "Ocurrió un error. Presione una tecla para volver a comprimir.";
                    Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (e.Length / 2)) + "}", e) + "\n");
                    Console.ReadKey();
                }
            }
        }
Exemplo n.º 5
0
 public ActionResult Insertar_LZW([FromBody] string path)
 {
     lZW.Compresion(path);
     return(Ok());
 }