/// <summary> /// Read all file content into array of bytes. Supports long file pathes > 260 characters /// </summary> public static byte[] ReadAllBytes([Localizable(false)] string path) { byte[] buffer; using (FileStream fileStream = FileStreamCreator.Create(path, FileMode.Open, FileAccess.Read)) { int offset = 0; long length = fileStream.Length; if (length > int.MaxValue) { throw new IOException("File too long."); } var count = (int)length; buffer = new byte[count]; while (count > 0) { int num = fileStream.Read(buffer, offset, count); if (num == 0) { break; } offset += num; count -= num; } } return(buffer); }
public override void Write(Stream stream) { FileStreamCreator originalStream = this.TryGetOriginalFileStreamCreator(); // optimization: Check if we have the data from the original file, and we don't need to encrypt and compress it again if (originalStream != null) { originalStream.WriteRaw(stream); } else { // we need to create it.. Stream baseStream = new StreamKeeper(stream); using (Stream input = this.Data.GetStream()) { using (Stream output = this.Compressed ? Platform.GetCompressStream(AES.EncryptStream(baseStream)) : baseStream) { input.CopyTo(output); } } } }