Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Generate ANSI table ...");

            ANSI ascii = new ANSI();

            ascii.WriteToFile();

            Console.WriteLine("ANSI table generated.");

            Console.WriteLine("Start encoding " + fileToCompress + " ...");

            string     text    = File.ReadAllText(fileToCompress, System.Text.ASCIIEncoding.Default);
            LZWEncoder encoder = new LZWEncoder();

            byte[] b = encoder.EncodeToByteList(text);
            File.WriteAllBytes(encodedFile, b);

            Console.WriteLine("File " + fileToCompress + " encoded to " + encodedFile);

            Console.WriteLine("Start decoding " + encodedFile);

            LZWDecoder decoder = new LZWDecoder();

            byte[] bo            = File.ReadAllBytes(encodedFile);
            string decodedOutput = decoder.DecodeFromCodes(bo);

            File.WriteAllText(decodedFile, decodedOutput, System.Text.Encoding.Default);

            Console.WriteLine("File " + encodedFile + " decoded to " + decodedFile);
        }
Example #2
0
        private void Compress(object sender, RoutedEventArgs e)
        {
            if (!filenameCom.fileIsEmpty())
            {
                string noteCompressed = @"D:\RealEncAndCom\noteCompressed.txt";
                File.Delete(noteCompressed);
                ANSI       ascii   = new ANSI();
                LZWEncoder encoder = new LZWEncoder();

                string text = File.ReadAllText(filenameCom, System.Text.Encoding.Default);
                ascii.WriteToFile();
                byte[] b = encoder.EncodeToByteList(text);
                File.WriteAllBytes(noteCompressed, b);
                comLabel1.Content = "Файл был сжат!";
            }
            else
            {
                comLabel1.Content = "Файл не был сжат!";
            }
        }