public static bool Compress(byte[] data, out byte[] compressed, int level) { DBPFCompression compressor = new DBPFCompression(level); compressed = compressor.Compress(data); return(compressed != null); }
public KeyValuePair <DBPFIndexEntry, byte[]> Export() { MemoryStream ms = new MemoryStream(); using (ms) { ms.Write(Encoding.ASCII.GetBytes("STBL"), 0, 4); BinaryWriter bw = new BinaryWriter(ms); bw.Write((byte)2); bw.Write((short)0); bw.Write((int)mEntries.Count); bw.Write((int)0); bw.Write((short)0); foreach (KeyValuePair <UInt64, string> entry in mEntries) { bw.Write(entry.Key); bw.Write((int)Encoding.Unicode.GetByteCount(entry.Value) / 2); bw.Write(Encoding.Unicode.GetBytes(entry.Value)); } } byte[] data = ms.ToArray(); byte[] compressed; if (DBPFCompression.Compress(data, out compressed)) { return(new KeyValuePair <DBPFIndexEntry, byte[]>(new DBPFIndexEntry(new DBPFReference(0x220557DA, 0, Instance), 0, (uint)compressed.Length, (uint)data.Length, true), compressed)); } else { return(new KeyValuePair <DBPFIndexEntry, byte[]>(new DBPFIndexEntry(new DBPFReference(0x220557DA, 0, Instance), 0, (uint)data.Length, (uint)data.Length, false), data)); } }