Beispiel #1
0
        /// <summary>
        /// Creates a bundle containing version list delta and all data of files.
        /// </summary>
        /// <returns>The binary bundle.</returns>
        /// <param name="list">List needed to transferred.</param>
        public static byte[] CreateFileBundle(List<FileEvent> list)
        {
            using (MemoryStream ms = new MemoryStream())
            using (ZipOutputStream zip = new ZipOutputStream(ms))
            {
                ZipEntry block = new ZipEntry("vs");
                zip.PutNextEntry(block);
                zip.WriteAllBytes(list.SerializeAsBytes());
                zip.CloseEntry();

                foreach (var sha1 in list.Where(x => x.SHA1 != null).Select(x => x.SHA1).Distinct())
                {
                    block = new ZipEntry(sha1);
                    zip.PutNextEntry(block);
                    zip.WriteAllBytes(File.ReadAllBytes(Config.MetaFolderData.File(sha1)));
                    zip.CloseEntry();
                }

                zip.Finish();
                ms.Flush();
                ms.Position = 0;

                return ms.ToArray();
            }
        }