コード例 #1
0
        private Task <string> GetChecksumAsync(AdapterHolder adapterHolder, string key, CancellationToken cancellationToken)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            return(GetChecksumAsyncImpl());

            async Task <string> GetChecksumAsyncImpl()
            {
                var adapter = await adapterHolder.GetAdapterAsync();

                await ThrowIfNotExistsAsync(adapter, key, cancellationToken);

                if (adapter is IChecksumCalculator checksumCalculator)
                {
                    return(await checksumCalculator.GetChecksumAsync(key, cancellationToken));
                }

                var bytes = await ReadAllBytesAsync(adapter, key, cancellationToken);

                return(ChecksumHelper.FromContent(bytes));
            }
        }