Example #1
0
        internal static byte[] Deflate(byte[] buffer, int sizeCompressed, int sizeDecompressed)
        {
            using (RecyclableMemoryStream tmp = new RecyclableMemoryStream())
            {
                BnSDatArchive.UncompressBuffer(buffer, tmp);

                if (tmp.Length != sizeDecompressed)
                {
                    byte[] tmp2 = new byte[sizeDecompressed];

                    if (tmp.Length > sizeDecompressed)
                    {
                        Array.Copy(tmp.GetBuffer(), 0, tmp2, 0, sizeDecompressed);
                    }
                    else
                    {
                        Array.Copy(tmp.GetBuffer(), 0, tmp2, 0, tmp.Length);
                    }
                    return(tmp2);
                }
                else
                {
                    return(tmp.ToArray());
                }
            }
        }
Example #2
0
        public static BnSDatArchive Read(Stream stream, bool leaveOpen, bool is64)
        {
            if (!stream.CanRead)
            {
                throw new InvalidOperationException("The stream should be readable");
            }
            BnSDatArchive dat = new BnSDatArchive(stream, leaveOpen, is64);

            dat.ReadHeader();
            return(dat);
        }
Example #3
0
        public static BnSDatWriter Modify(string filename, bool is64)
        {
            FileStream   fs     = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
            BnSDatWriter result = BnSDatWriter.Create(fs, false);

            using (BnSDatArchive archive = BnSDatArchive.Read(fs, true))
                using (IReader reader = archive.ExtractAllEntries())
                    while (reader.MoveToNextEntry())
                    {
                        reader.CopyEntryTo(result);
                    }
            return(result);
        }
Example #4
0
 public static BnSDatArchive Read(Stream stream, bool leaveOpen) => BnSDatArchive.Read(stream, leaveOpen, false);
Example #5
0
 public static BnSDatArchive Read(Stream stream) => BnSDatArchive.Read(stream, false);
Example #6
0
 public static BnSDatArchive Read(string filename) => BnSDatArchive.Read(filename, false);