public async Task <uint> GetLastKeyAsync(CancellationToken cancel = new CancellationToken()) { // We need to look into the last blob, so we need to list all blobs first await RefreshCache(cancel); // Look into the last non-empty blob if (_firstKey.Count == 0) { return(0); } var blob = _blobs[_firstKey.Count - 1]; // Download one event's worth of data to a local buffer. // This will likely truncate an event somewhere at the beginning of the // buffer, but we don't care, because looking for the *last* sequence only // requires that the last event in the buffer isn't truncated. var length = Math.Min(EventFormat.MaxEventFootprint, blob.Properties.Length); var bytes = new byte[length]; await ReadSubRangeAsync(blob, bytes, blob.Properties.Length - length, 0, length, cancel); // Look for the sequence number of the last event. using (var stream = new MemoryStream(bytes)) return(await EventFormat.GetLastSequenceAsync(stream, cancel)); }
public async Task <uint> GetLastKeyAsync(CancellationToken cancel = new CancellationToken()) => await EventFormat.GetLastSequenceAsync(_file, cancel);