Example #1
0
        public void ZipHuffman(string path, string fileName, params string[] files)
        {
            _tree = new HuffmanAlgorithmTree();

            using (var writer = new BinaryWriter(File.OpenWrite(path + "\\" + fileName + ".hz"), Encoding.Default))
            {
                var onlyFiles = GetOnlyFiles(files);
                writer.Write(BitConverter.GetBytes(onlyFiles.Count));

                ExecuteParams.Max          = onlyFiles.Count;
                ExecuteParams.CurrentValue = 0;
                ExecuteParams.Start        = true;

                ExecuteParams.Str = "Write tree...";
                WriteTree(writer, BuildTree(onlyFiles.ToArray()));
                ExecuteParams.Str += "---OK\n";

                foreach (var file in files)
                {
                    CreateEncodeFiles(file, writer);
                }

                ExecuteParams.Str += "End encoding\n";
                System.Threading.Thread.Sleep(1000);
                ExecuteParams.Start = false;
            }
        }
Example #2
0
        private void ReadTree(BinaryReader reader, int size)
        {
            var treeName = $"{Guid.NewGuid().ToString()}.bin";

            using (var fs = new FileStream(treeName, FileMode.CreateNew))
            {
                fs.Write(reader.ReadBytes(size), 0, size);
                fs.Position = 0;
                _tree       = new BinaryFormatter().Deserialize(fs) as HuffmanAlgorithmTree;
            }

            File.Delete(treeName);
        }