コード例 #1
0
ファイル: ByteWriter.cs プロジェクト: romkatv/ChunkIO
 public async Task FlushAsync(bool flushToDisk)
 {
     if (ErrorInjector != null)
     {
         await ErrorInjector.FlushAsync(_file, flushToDisk);
     }
     // The flush API in FileStream is f****d up:
     //
     //   * FileStream.Flush(flushToDisk) synchronously flushes to OS and then optionally synchronously
     //     flushes to disk.
     //   * FileStream.FlushAsync() synchronously flushes to OS and then asynchronously flushes to disk.
     //
     // To add insult to injury, when called without arguments, FileStream.Flush() doesn't flush to disk
     // while FileStream.FlushAsync() does!
     //
     // Based on this API we implement ByteWriter.FlushAsync(flushToDisk) that synchronously flushes to OS
     // and then optionally asynchronously flushes to disk. Not perfect but the best we can do.
     if (flushToDisk)
     {
         await _file.FlushAsync();
     }
     else
     {
         _file.Flush(flushToDisk: false);
     }
 }
コード例 #2
0
 public async Task <int> ReadAsync(byte[] array, int offset, int count)
 {
     if (ErrorInjector != null)
     {
         await ErrorInjector.ReadAsync(_file, array, offset, count);
     }
     return(await _file.ReadAsync(array, offset, count));
 }
コード例 #3
0
ファイル: ByteWriter.cs プロジェクト: romkatv/ChunkIO
 public async Task WriteAsync(byte[] array, int offset, int count)
 {
     if (ErrorInjector != null)
     {
         await ErrorInjector?.WriteAsync(_file, array, offset, count);
     }
     await _file.WriteAsync(array, offset, count);
 }
コード例 #4
0
 public void Seek(long position)
 {
     ErrorInjector?.Seek(_file, position);
     if (position == _file.Position)
     {
         return;
     }
     if (_file.Seek(position, SeekOrigin.Begin) != position)
     {
         throw new IOException($"Cannot seek to {position}");
     }
 }