Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void CreateFile(string path)
- {
- Task<byte[]> headerTask = CreateHeaderAsync();
- Task<byte[]> filesTask = CombineFilesAsync();
- byte[] header = headerTask.Result;
- byte[] files = filesTask.Result;
- byte[] combined = new byte[header.Length + files.Length];
- Buffer.BlockCopy(header, 0, combined, 0, header.Length);
- Buffer.BlockCopy(files, 0, combined, header.Length, files.Length);
- Task.Factory.StartNew(() => File.WriteAllBytes(path, combined));
- }
- private Task<byte[]> CreateHeaderAsync()
- {
- return Task.Factory.StartNew(() =>
- {
- StringBuilder sb = new StringBuilder();
- int position = 0;
- foreach (ByteFile file in _files)
- {
- sb.Append(file + "?" + position + Environment.NewLine);
- position += file.Length;
- }
- return Encoding.UTF8.GetBytes(sb + "--header_end--" + Environment.NewLine);
- });
- }
- private Task<byte[]> CombineFilesAsync()
- {
- return Task.Factory.StartNew(() =>
- {
- ByteFile[] arrays = _files.ToArray();
- byte[] rv = new byte[arrays.Sum(a => a.Length)];
- int offset = 0;
- foreach (ByteFile t in arrays)
- {
- var array = Encryption.EncryptBytes(t.Content, "password");
- var array = t.Content;
- Buffer.BlockCopy(array, 0, rv, offset, array.Length);
- offset += array.Length;
- }
- return rv;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement