public async ValueTask WriteAsync(OmniHash rootHash, OmniHash targetHash, ReadOnlyMemory <byte> memory, CancellationToken cancellationToken = default) { using (await _asyncLock.LockAsync()) { if (!_wantFileStatusMap.TryGetValue(rootHash, out var status) || !status.WantBlocks.Contains(targetHash)) { return; } var filePath = Path.Combine(Path.Combine(_configPath, this.OmniHashToFilePath(rootHash)), this.OmniHashToFilePath(targetHash)); if (File.Exists(filePath)) { return; } using (var fileStream = new UnbufferedFileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, FileOptions.None, _bytesPool)) { await fileStream.WriteAsync(memory); } status.WantBlocks.Remove(targetHash); } }
private async ValueTask WriteAsync(string basePath, OmniHash hash, ReadOnlyMemory <byte> memory) { var filePath = Path.Combine(basePath, this.OmniHashToFilePath(hash)); using (var fileStream = new UnbufferedFileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, FileOptions.None, _bytesPool)) { await fileStream.WriteAsync(memory); } }