Exemple #1
0
        public ActionResult LecturaCompresión(HttpPostedFileBase postedFile)
        {
            string ArchivoLeido = string.Empty;
            //le permite corroborar si la carpeta Files ya existe en la solución
            bool   Exists;
            string Paths = Server.MapPath("~/Files/");

            Exists = Directory.Exists(Paths);
            if (!Exists)
            {
                Directory.CreateDirectory(Paths);
            }
            //el siguiente if permite seleccionar un archivo en específico
            if (postedFile != null)
            {
                string rutaDirectorioUsuario = Server.MapPath(string.Empty);
                //se toma la ruta y nombre del archivo
                ArchivoLeido = rutaDirectorioUsuario + Path.GetFileName(postedFile.FileName);
                // se añade la extensión del archivo
                RutaArchivos = rutaDirectorioUsuario;
                postedFile.SaveAs(ArchivoLeido);
                ArchivoOriginal = ArchivoLeido;
                LZWCompressor LZWLectura = new LZWCompressor();
                diccionario = LZWLectura.LecturaArchivo(ArchivoLeido, bufferLengt, diccionario, RutaArchivos);
            }
            return(RedirectToAction("MétodoLZW", new RouteValueDictionary(new { Controller = "CompresorLZW", Action = "MétodoLZW", ArchivoLeido })));
        }
Exemple #2
0
        public ActionResult MétodoLZWDescompresion()
        {
            LZWCompressor LZW   = new LZWCompressor();
            string        texto = LZW.Descompress(diccionario, ASCII, CantidadBitsRequeridos, RutaArchivos);

            return(RedirectToAction("Download"));
        }
Exemple #3
0
        public void AlgorithmsTest()
        {
            LZWCompressor.Compress(_inputFilePath, _archivedFilePath);
            HuffmanDeCompressor.DeCompress(_archivedFilePath, _outputFilePath);
            CompareFiles();

            HuffmanTestWithDifferentFilesLength(25);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Ingrese el texto para codificar");
            string text = Console.ReadLine();
            var    lzw  = new LZWCompressor("..//..//..");

            Console.WriteLine("El texto comprimido es:");
            Console.WriteLine(lzw.ShowCompress(text));
            Console.ReadLine();
        }
Exemple #5
0
        private void AlgorithmsCompressDecompressWithLength(int count)
        {
            var str                   = CreateStringWithLength(count);
            var newFileLocation       = Data.Location + count;
            var newOutputFileLocation = newFileLocation + "out";

            File.WriteAllText(Data.Location + count, str);

            LZWCompressor.Compress(newFileLocation, _archivedFilePath);
            HuffmanDeCompressor.DeCompress(_archivedFilePath, newOutputFileLocation);
            CompareFiles(newFileLocation, newOutputFileLocation);
        }
 public IActionResult Compress([FromForm] IFormFile file, string name)
 {
     try
     {
         string path = env.ContentRootPath + "\\" + file.FileName;
         using var saver = new FileStream(path, FileMode.Create);
         file.CopyTo(saver);
         saver.Close();
         using var fileWritten = new FileStream(path, FileMode.OpenOrCreate);
         using var reader      = new BinaryReader(fileWritten);
         byte[] buffer = new byte[0];
         while (fileWritten.Position < fileWritten.Length)
         {
             int index = buffer.Length;
             Array.Resize <byte>(ref buffer, index + 100000);
             byte[] aux = reader.ReadBytes(100000);
             aux.CopyTo(buffer, index);
         }
         reader.Close();
         fileWritten.Close();
         for (int i = 0; i < buffer.Length; i++)
         {
             if (buffer[i] == 0)
             {
                 Array.Resize <byte>(ref buffer, i);
                 break;
             }
         }
         if (buffer.Length > 0)
         {
             var compressor = new LZWCompressor(env.ContentRootPath);
             path = compressor.Compress(buffer, file.FileName, name);
             var fileStream = new FileStream(path, FileMode.OpenOrCreate);
             return(File(fileStream, "text/plain"));
         }
         else
         {
             return(StatusCode(500, "El archivo está vacío"));
         }
     }
     catch
     {
         return(StatusCode(500));
     }
 }
Exemple #7
0
        static void Main(string[] args)
        {
            //string inputFilePath = "";
            //string archivedFilePath = "";
            //switch (args.Length)
            //{
            //    case 2:
            //        inputFilePath = args[0];
            //        archivedFilePath = args[1];
            //        break;
            //    case 4:
            //        switch (args[0])
            //        {
            //            case "-i":
            //                inputFilePath = args[1];
            //                archivedFilePath = args[3];
            //                break;
            //            case "-o":
            //                archivedFilePath = args[1];
            //                inputFilePath = args[3];
            //                break;
            //            default:
            //                ThrowWrongInput();
            //                return;
            //        }
            //        break;
            //    default:
            //        ThrowWrongInput();
            //        return;
            //}

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            LZWCompressor.Compress(Data.InputFilePath, Data.ArchivedFilePath);
            stopWatch.Stop();
            Console.WriteLine(stopWatch.ElapsedMilliseconds);
            Console.ReadLine();
            //stopWatch.Start();
            //LZWCompressor.Compress(Data.Location + "file.txt", Data.Location + "archived.txt");
            //stopWatch.Stop();
            //Console.WriteLine(stopWatch.ElapsedMilliseconds);
        }
 public IActionResult Decompress([FromForm] IFormFile file)
 {
     try
     {
         string path = env.ContentRootPath + "\\" + file.FileName;
         using var saver = new FileStream(path, FileMode.Create);
         file.CopyTo(saver);
         using var reader = new StreamReader(saver);
         saver.Position   = 0;
         var text       = reader.ReadToEnd();
         var compressor = new LZWCompressor(env.ContentRootPath);
         path = compressor.Decompress(text);
         var fileStream = new FileStream(path, FileMode.OpenOrCreate);
         return(File(fileStream, "text/plain"));
     }
     catch
     {
         return(StatusCode(500));
     }
 }
Exemple #9
0
        public ActionResult MétodoLZW(string ArchivoLeido)
        {
            LZWCompressor LZW                   = new LZWCompressor();
            var           ListaValores          = new List <string>();
            var           ListaBytesComprimidos = new List <byte>();

            diccionario = LZW.CompararCaracteres(diccionario, ref ListaValores, bufferLengt, ArchivoLeido);
            //convertirlos a bytes
            var valorCadena = LZW.CuantosBitsSeNecesitan(diccionario.Count());

            byte[] bytebuffer = LZW.CreaciónBufferEscritura(diccionario, ListaValores, ListaBytesComprimidos, valorCadena);
            using (var writeStream = new FileStream(RutaArchivos + "\\..\\Files\\archivoComprimido.lzw", FileMode.Open))
            {
                using (var writer = new BinaryWriter(writeStream))
                {
                    writer.Seek(0, SeekOrigin.Begin);
                    writer.Write(Convert.ToByte(valorCadena));
                    writer.Seek(0, SeekOrigin.End);
                    writer.Write(bytebuffer);
                }
            }
            return(RedirectToAction("Download"));
        }
Exemple #10
0
            public void Post(string RServerPath)
                {
                string WServerPath = "";

                if (RServerPath != "")
                {
                    /*All the pre-compress path preparation*/
                    LZWCompressor lz = new LZWCompressor();
                    string        ServerDirectory = Directory.GetCurrentDirectory();
                    string        path            = Path.Combine(ServerDirectory, "Decompress/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    WServerPath = path + Path.GetFileName(RServerPath);
                    /*Compress the file*/
                    lz.Decompress(RServerPath, WServerPath);

                    /*adds the compression to the history*/
                    string HistLine = lz.GetFilesMetrics(Path.GetFileName(RServerPath), RServerPath, WServerPath);
                    History.AddToHistory(HistLine);
                    this.WriteOnHistory(HistLine);
                }
            }
        public IEnumerable <Compression> GetCompressions()
        {
            var compressor = new LZWCompressor(env.ContentRootPath);

            return(compressor.GetCompressions());
        }