internal byte[] SerializeMetadata(List <FileInfo> fileInfos) { byte[] buffer; if (fileInfos.Count > FileInfo.MAX_FILE) { throw new ArgumentException("Too many files"); } using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms, Encoding.UTF8)) { bw.Write((byte)MAGIC_BYTE); // 1 byte bw.Write((Int32)fileInfos.Count); // 2 byte foreach (var fi in fileInfos) { bw.Write(BinSerializer.SerializeStringInUTF8(fi.FileName, FileInfo.MAX_FILE_NAME_SIZE)); // 16 bw.Write((Int32)fi.StartPage); // 4 byte bw.Write((Int32)fi.Length); // 4 byte bw.Write(fi.Created.Ticks); // 8 bytes } } buffer = ms.ToArray(); buffer = BinSerializer.PadBuffer(buffer, FAT_END_ADDR); return(buffer); } }
/// <summary> /// Convert the FAT data into a byte array /// </summary> /// <param name="fileInfos"></param> /// <returns></returns> internal byte[] SerializeFAT() { byte[] buffer; if (FileInfos.Count > MAX_FILE_PER_FAT) { throw new ArgumentException("Too many files"); } using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms, Encoding.UTF8)) { bw.Write((byte)MAGIC_BYTE); // 1 byte bw.Write((Int32)FileInfos.Count); // 4 byte foreach (var fi in FileInfos) { bw.Write(BinSerializer.SerializeStringInUTF8(fi.FileName, sFsFileInfo.MAX_FILE_NAME_SIZE)); // 32 bytes bw.Write((Int32)fi.StartPage); // 4 bytes bw.Write((Int32)fi.Length); // 4 bytes bw.Write(fi.LastModificationDate.Ticks); // 8 bytes } } buffer = ms.ToArray(); buffer = BinSerializer.PadBuffer(buffer, FAT_END_ADDR); return(buffer); } }