Esempio n. 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);
        }
Esempio n. 2
0
        private void btnPack_Click(object sender, EventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();

            if (opf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtPath.Text = opf.FileName;

                var        text    = File.ReadAllText(opf.FileName, System.Text.ASCIIEncoding.Default);
                LZWEncoder encoder = new LZWEncoder();

                var buffer = encoder.EncodeToByteList(text);
                File.WriteAllBytes(opf.FileName + ".lzw", buffer);

                MessageBox.Show("Encoding complete.");
            }
        }
Esempio n. 3
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 = "Файл не был сжат!";
            }
        }
Esempio n. 4
0
        public static void Do()
        {
            Console.WriteLine("Generate ANSI table ...");
            var ascii = new Ansi();

            ascii.WriteToFile();
            Console.WriteLine("ANSI table generated.");
            Console.WriteLine("Start encoding " + _fileToCompress + " ...");
            var text    = File.ReadAllText(_fileToCompress);
            var encoder = new LZWEncoder();
            var b       = encoder.EncodeToByteList(text);

            File.WriteAllBytes(_encodedFile, b);
            Console.WriteLine("File " + _fileToCompress + " encoded to " + _encodedFile);
            Console.WriteLine("Start decoding " + _encodedFile);
            var decoder       = new LZWDecoder();
            var bo            = File.ReadAllBytes(_encodedFile);
            var decodedOutput = decoder.DecodeFromCodes(bo);

            File.WriteAllText(_decodedFile, decodedOutput, Encoding.Default);
            Console.WriteLine("File " + _encodedFile + " decoded to " + _decodedFile);
        }