public void ExportTextsToExcelFile(string where, byte[] uncompressedData)
        {
            StringChunk strChunk = new StringChunk(uncompressedData);

            Liner[] allLiners = strChunk.allLiners;

            ExcelPackage   pck = new ExcelPackage(File.Open(where, FileMode.Create));
            ExcelWorksheet ws  = pck.Workbook.Worksheets.Add("Satirlar");

            ws.Cells["A1"].Value = "Orjinal Satır";
            ws.Cells["B1"].Value = "Türkçe Satır";
            ws.Cells["C1"].Value = "Grup";
            ws.Cells["D1"].Value = "Id";
            ws.Cells["E1"].Value = "Pos";
            ws.Cells["A1:E1"].Style.Font.Bold = true;

            for (int i = 0; i < allLiners.Length; i++)
            {
                Liner lin = allLiners[i];
                ws.Cells["A" + (i + 2)].Value = allLiners[i].line;
                ws.Cells["C" + (i + 2)].Value = allLiners[i].grup;
                ws.Cells["D" + (i + 2)].Value = allLiners[i].id;
                ws.Cells["E" + (i + 2)].Value = allLiners[i].subPos;
            }

            pck.Save();
            pck.Dispose();
        }
        public byte[] compressGermanLZ4(string excelPath)
        {
            Liner[] liners       = ImportFromExcelFile(excelPath);
            byte[]  allLineBytes = liners.SelectMany(p => p.lineBytes).ToArray();

            MemoryStream compressedMem = new MemoryStream();

            using (BinaryWriter binwr = new BinaryWriter(compressedMem))
            {
                byte[] header       = new byte[] { 0x00, 0x90, 0x03, 0x00 };
                int    lineCount    = liners.Length;
                int    idStartPos   = 140 + 8;
                int    textStartPos = 63964 + 8;
                int    unpackedSize = allLineBytes.Length + textStartPos - 8;
                byte[] global       = new byte[] { 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C };

                binwr.Write(header);
                binwr.Write(unpackedSize);
                binwr.Write(lineCount);
                binwr.Write(idStartPos - 8);
                binwr.Write(textStartPos - 8);
                binwr.Write(global);

                DecompressedDataLength = unpackedSize;

                while (binwr.BaseStream.Position < (idStartPos))
                {
                    binwr.Write((byte)0x0);
                }

                Liner[] linersOrderedByIds = liners.OrderBy(p => p.id).ToArray();
                for (int i = 0; i < linersOrderedByIds.Length; i++)
                {
                    Liner lin = linersOrderedByIds[i];
                    binwr.Write(lin.id);
                    binwr.Write((Int16)lin.subPos);
                    binwr.Write((Int16)lin.grup);
                }

                binwr.Write(allLineBytes, 0, allLineBytes.Length);
            }

            return(CompressData(compressedMem.ToArray()));
        }
        private void readData(byte[] data)
        {
            using (binred = new BinaryReader(new MemoryStream(data)))
            {
                binred.BaseStream.Position = 4; //skip header
                uint extractedSize = binred.ReadUInt32();
                uint lineCount     = binred.ReadUInt32();
                uint idStartPos    = binred.ReadUInt32() + mainOffset;
                uint textStartPos  = binred.ReadUInt32() + mainOffset;
                binred.ReadBytes(6);//Globals

                allLiners = new Liner[lineCount];

                binred.BaseStream.Position = idStartPos;
                for (int i = 0; i < lineCount; i++)
                {
                    Liner lin = new Liner();
                    lin.id     = binred.ReadUInt32();
                    lin.subPos = binred.ReadUInt16();
                    lin.grup   = binred.ReadUInt16();
                    long tempPos = binred.BaseStream.Position;

                    binred.BaseStream.Position = textStartPos + lin.grup * 65536 + lin.subPos;
                    lin.lineBytes = Tools.ReadTillNull(binred);

                    //x00 null, x0A newline, xA0 hardspace
                    lin.line = Encoding.GetEncoding("ISO-8859-1").GetString(lin.lineBytes).TrimEnd('\x00');
                    for (var k = 0; k < lin.line.Length; k++)
                    {
                        byte chB = (byte)lin.line[k];
                        if ((chB > 129 && chB < 209) || chB < 32)
                        {
                            lin.line = lin.line.Replace(lin.line[k].ToString(), "<*" + chB.ToString() + ">");
                        }
                    }
                    allLiners[i] = lin;
                    binred.BaseStream.Position = tempPos;
                }

                allLiners = allLiners.OrderBy(p => p.grup).ThenBy(p => p.subPos).ToArray();
            }
        }
        public Liner[] ImportFromExcelFile(string where)
        {
            ExcelPackage   pck = new ExcelPackage(File.Open(where, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
            ExcelWorksheet ws  = pck.Workbook.Worksheets.ElementAt(0);

            List <Liner> importedLiners = new List <Liner>();

            uint curPos = 0;

            for (int i = 2; i <= ws.Dimension.Rows; i++)
            {
                Liner  lin = new Liner();
                string str = "";

                if (ws.Cells["B" + (i)].Value != null && ws.Cells["B" + (i)].Value.ToString() != "")
                {
                    str = ws.Cells["B" + (i)].Value.ToString();//take from translated first,
                }
                else if (ws.Cells["A" + (i)].Value != null)
                {
                    str = ws.Cells["A" + (i)].Value.ToString();
                }
                lin.line      = str;
                str           = ConvertBackUnicodes(str);
                lin.lineBytes = Encoding.GetEncoding("ISO-8859-1").GetBytes(str + '\x00');

                lin.id = uint.Parse(ws.Cells["D" + (i)].Value.ToString());

                lin.grup   = curPos / 65536;
                lin.subPos = curPos % 65536;
                curPos     = (curPos + (uint)lin.lineBytes.Length);
                importedLiners.Add(lin);
            }

            pck.Dispose();

            return(importedLiners.ToArray());
        }
        public byte[] compressLZ4(string excelPath)
        {
            Liner[] liners       = ImportFromExcelFile(excelPath);
            byte[]  allLineBytes = liners.SelectMany(p => p.lineBytes).ToArray();

            MemoryStream compressedMem = new MemoryStream();

            using (BinaryWriter binwr = new BinaryWriter(compressedMem))
            {
                byte[] header       = new byte[] { 0x00, 0x01, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00 };
                int    lineCount    = liners.Length;
                int    idStartPos   = 140 + 16;
                int    textStartPos = 63964 + 16;
                int    unpackedSize = allLineBytes.Length + textStartPos - 8;
                byte[] global       = new byte[] { 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C };

                binwr.Write(header);
                binwr.Write(unpackedSize);
                binwr.Write(lineCount);
                binwr.Write(idStartPos - 16);
                binwr.Write(textStartPos - 16);
                binwr.Write(global);

                DecompressedDataLength = unpackedSize;

                while (binwr.BaseStream.Position < (idStartPos))
                {
                    binwr.Write((byte)0);
                }

                Liner[] linersOrderedByIds = liners.OrderBy(p => p.id).ToArray();
                for (int i = 0; i < linersOrderedByIds.Length; i++)
                {
                    Liner lin = linersOrderedByIds[i];

                    binwr.Write(lin.id);
                    binwr.Write((Int16)lin.subPos);
                    binwr.Write((Int16)lin.grup);
                }

                int uncompressedRemaining = 65536 + 8 - (textStartPos);
                for (int i = 0; i < uncompressedRemaining; i++)
                {
                    binwr.Write(allLineBytes[i]);
                }

                int hold = uncompressedRemaining;
                while (hold < allLineBytes.Length)
                {
                    if (hold + 65536 < allLineBytes.Length)
                    {
                        byte[] temp = new byte[65536];
                        Array.Copy(allLineBytes, hold, temp, 0, 65536);
                        byte[] aa = compressBlock(temp, hold);
                        binwr.Write(aa);
                        hold += 65536;
                    }
                    else
                    {
                        int    remaining = allLineBytes.Length - hold;
                        byte[] temp      = new byte[remaining];
                        Array.Copy(allLineBytes, hold, temp, 0, remaining);
                        binwr.Write(compressBlock(temp, hold));
                        hold += remaining;
                    }

                    Console.WriteLine(hold + " OK...");
                }
            }


            compressedData = compressedMem.ToArray();
            return(compressedData);
        }