Пример #1
0
        public static string HuffmanDecompress(string huffCompressed)
        {
            HuffmanCoder h = new HuffmanCoder();

            h.CompressedObject = huffCompressed;
            return(h.DecompressedObject);
        }
Пример #2
0
        public void Post(string RServerPath)
        {
            //var UploadedFile = Request.Form.Files[0];
            string WServerPath = "";

            if (RServerPath != "")
            {
                HuffmanCoder hf = new HuffmanCoder();
                string       ServerDirectory = Directory.GetCurrentDirectory();
                string       path            = Path.Combine(ServerDirectory, "Decompress/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                WServerPath = path + Path.GetFileName(RServerPath);
                //FileStream ServerFile = new FileStream(RServerPath, FileMode.Create, FileAccess.ReadWrite);
                //UploadedFile.CopyTo(ServerFile);
                //ServerFile.Close();
                string file = hf.uncompress(RServerPath);
                using (FileStream FileToWrite = new FileStream(WServerPath, FileMode.CreateNew))
                {
                    FileToWrite.Write(Encoding.Default.GetBytes(file));
                }
                string HistLine = hf.GetFilesMetrics(Path.GetFileName(RServerPath), RServerPath, WServerPath);
                History.AddToHistory(HistLine);
                this.WriteOnHistory(HistLine);
            }
        }
Пример #3
0
        public static string HuffmanCompress <T>(T decompressed) where T : class
        {
            HuffmanCoder <T> h = new HuffmanCoder <T>();

            h.DecompressedObject = decompressed;
            return(h.CompressedObject);
        }
Пример #4
0
        public void TenRandomPokemon()
        {
            HuffmanCoder huff    = new HuffmanCoder();
            HuffmanCoder huffTwo = new HuffmanCoder();

            for (int i = 0; i < 10; i++)
            {
                string temp = huff.DecompressedObject = PokeAPI.DataFetcher.GetJsonOfAny(new Uri($"https://pokeapi.co/api/v2/pokemon/{rand.Next(808)}")).Result.ToJson();
                huffTwo.CompressedObject = huff.CompressedObject;
                Assert.True(huffTwo.DecompressedObject == temp);
            }
        }
Пример #5
0
        public static void Main(string[] args)
        {
            var path        = "testfile.txt";
            var huffman     = new HuffmanCoder(new DictionaryService());
            var fileService = new FileService();
            var plainText   = fileService.LoadData(path);

            var cipher = huffman.Encode(plainText);

            fileService.SaveData("cipher.txt", cipher);

            var loadedCipher = fileService.LoadData("cipher.txt");
            var decrypted    = huffman.Decode(loadedCipher);

            fileService.SaveData("decoded.txt", decrypted);
        }
Пример #6
0
        public void Encode_FourNodes_BalancedTree()
        {
            //given
            var tree  = MockHuffmanTreeBuilder.Build('#', '#', 'a', 'b', 'c', 'd');
            var coder = new HuffmanCoder <char>(tree);
            var input = new MockCoderInput <char>(new List <char>()
            {
                'a', 'b', 'c', 'd'
            });
            var output = new MockCoderOutput();

            //when
            coder.Encode(input, output);
            //then
            output.AssertEquals(new List <int>()
            {
                0, 0, 0, 1, 1, 0, 1, 1
            });
        }
Пример #7
0
        public void Encode_ThreeNodes_TwoAreRight()
        {
            //given
            var tree  = MockHuffmanTreeBuilder.Build('c', '#', 'b', 'a');
            var coder = new HuffmanCoder <char>(tree);
            var input = new MockCoderInput <char>(new List <char>()
            {
                'a', 'b', 'c'
            });
            var output = new MockCoderOutput();

            //when
            coder.Encode(input, output);
            //then
            output.AssertEquals(new List <int>()
            {
                1, 1, 1, 0, 0
            });
        }
Пример #8
0
        public void Post(string RServerPath, string newname)
        {
            //var UploadedFile = Request.Form.Files[0];
            string WServerPath = "";

            if (RServerPath != "")
            {
                HuffmanCoder hf = new HuffmanCoder();
                string       ServerDirectory = Directory.GetCurrentDirectory();
                string       path            = Path.Combine(ServerDirectory, "Compress/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                WServerPath = path + newname + ".huff";
                //FileStream ServerFile = new FileStream(RServerPath, FileMode.Create, FileAccess.ReadWrite);
                //UploadedFile.CopyTo(ServerFile);
                //ServerFile.Close();
                hf.Compress(RServerPath, WServerPath);
                string HistLine = hf.GetFilesMetrics(Path.GetFileName(RServerPath), RServerPath, WServerPath);
                History.AddToHistory(HistLine);
                this.WriteOnHistory(HistLine);
            }
        }