Ejemplo n.º 1
0
 private static void Compress(string filename, Stream file)
 {
     using (var output = new FileStream($"{filename}{Extension}", FileMode.Create, FileAccess.Write))
     {
         output.WriteCharacters(Header);
         output.WriteUInt(Version);
         output.Position += 4;
         output.WriteUInt((uint)file.Length);
         LZSS.Compress(file, output);
         output.Position = 8;
         output.WriteUInt((uint)(output.Length - 16));
     }
 }
Ejemplo n.º 2
0
            public void CompressSimpleTextNoPointersByteArraysOnly()
            {
                byte[] inputBytes = { 97, 98, 99 };
                var    inputFile  = new DataFile();

                inputFile.LoadBytes(inputBytes);
                byte[] expected = { 48, 152, 140, 96 };

                var comp   = new LZSS();
                var output = comp.Compress(inputFile);
                var actual = output.GetBytes(0, output.Length);

                Assert.AreEqual(expected, actual);
            }
Ejemplo n.º 3
0
            public void CompressSimpleText()
            {
                var expectedPath = TestContext.CurrentContext.TestDirectory + "../../../res/compressedTestFile";
                var expectedFile = new DataFile(expectedPath);
                var inputPath    = TestContext.CurrentContext.TestDirectory + "../../../res/testfile2";
                var inputFile    = new DataFile(inputPath);

                var comp       = new LZSS();
                var actualFile = comp.Compress(inputFile);

                Assert.AreEqual(expectedFile.GetBytes(0, expectedFile.Length),
                                actualFile.GetBytes(0, actualFile.Length));
                ;
            }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                return;
            }

            using (FileStream input = new FileStream(args[0], FileMode.Open))
            {
                using (FileStream output = new FileStream(args[0] + "_compressed", FileMode.Create))
                {
                    LZSS.Compress(input, output);
                }
            }
        }
Ejemplo n.º 5
0
            public void CompressSimpleTextPointers()
            {
                var inputPath = TestContext.CurrentContext.TestDirectory + "../../../res/testfile3";
                var inputFile = new DataFile(inputPath);

                byte[] expectedData = { 48, 152, 140, 102, 72, 1, 152 };
                var    expected     = new DataFile();

                expected.LoadBytes(expectedData);

                var comp   = new LZSS();
                var actual = comp.Compress(inputFile);

                Assert.AreEqual(expected.GetBytes(0, expected.Length), actual.GetBytes(0, actual.Length));
            }
Ejemplo n.º 6
0
            public void CompressSimpleTextNoPointersDataFile()
            {
                var inputPath = TestContext.CurrentContext.TestDirectory + "../../../res/testfile1";
                var inputFile = new DataFile(inputPath);

                byte[] expectedData = { 48, 152, 140, 96 };
                var    expected     = new DataFile();

                expected.LoadBytes(expectedData);

                var comp   = new LZSS();
                var actual = comp.Compress(inputFile);

                Assert.IsTrue(DataFile.Compare(expected, actual));
            }
Ejemplo n.º 7
0
        private void button_NetworkControl_Disconnect_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream("far.exe", FileMode.Open);

            byte[] uncomp = new byte[fs.Length];

            fs.Read(uncomp, 0, uncomp.Length);

            ICompression iCompressionArray_obj = new LZSS(8, true, true, false, 131072);

            DateTime dt1 = DateTime.Now;

            byte [] compress = iCompressionArray_obj.Compress(uncomp, false);

            DateTime dt2 = DateTime.Now;

            TimeSpan ts1 = dt2 - dt1;

            MessageBox.Show(ts1.Minutes.ToString() + ":" + ts1.Seconds.ToString() + ":" + ts1.Milliseconds.ToString());
        }
Ejemplo n.º 8
0
        public static byte[] ToData(LPack Pack)
        {
            using (MemoryStream Output = new MemoryStream())
            {
                BinaryWriter Writer = new BinaryWriter(Output);

                Writer.Write(Pack.Files.Length);
                Writer.Write(0u); //Total decompressed length Place Holder

                uint DataAddress   = (uint)(8 + Pack.Files.Length * 8);
                uint FileDecLength = 0;

                for (int i = 0; i < Pack.Files.Length; i++)
                {
                    Output.Seek(8 + i * 8, SeekOrigin.Begin);

                    Utils.WriteUInt24(Writer, (uint)Pack.Files[i].Data.Length);
                    Writer.Write(Pack.Files[i].FileId);
                    Writer.Write(DataAddress);

                    Output.Seek(DataAddress, SeekOrigin.Begin);

                    byte[] Comp = LZSS.Compress(Pack.Files[i].Data);

                    Writer.Write(Comp);

                    DataAddress   += (uint)Comp.Length;
                    FileDecLength += (uint)Pack.Files[i].Data.Length;
                }

                Output.Seek(4, SeekOrigin.Begin);
                Writer.Write(FileDecLength);

                return(Output.ToArray());
            }
        }