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()); } } }
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); }
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); }
public static BnSDatArchive Read(Stream stream, bool leaveOpen) => BnSDatArchive.Read(stream, leaveOpen, false);
public static BnSDatArchive Read(Stream stream) => BnSDatArchive.Read(stream, false);
public static BnSDatArchive Read(string filename) => BnSDatArchive.Read(filename, false);