public LazyLoadingReadOnlyStream(
            DownloadInternalAsync downloadInternalFunc,
            GetPropertiesAsync getPropertiesFunc,
            DownloadTransactionalHashingOptions hashingOptions,
            bool allowModifications,
            long initialLenght,
            long position  = 0,
            int?bufferSize = default)
        {
            _downloadInternalFunc      = downloadInternalFunc;
            _getPropertiesInternalFunc = getPropertiesFunc;
            _position   = position;
            _bufferSize = bufferSize ?? Constants.DefaultStreamingDownloadSize;
            _buffer     = ArrayPool <byte> .Shared.Rent(_bufferSize);

            _allowBlobModifications = allowModifications;
            _bufferPosition         = 0;
            _bufferLength           = 0;
            _length            = initialLenght;
            _bufferInvalidated = false;

            // the caller to this stream cannot defer validation, as they cannot access a returned hash
            if (!(hashingOptions?.Validate ?? true))
            {
                throw Errors.CannotDeferTransactionalHashVerification();
            }
            // we defer hash validation on download calls to validate in-place with our existing buffer
            _hashingOptions = hashingOptions == default
                ? default
                : new DownloadTransactionalHashingOptions
            {
                Algorithm = hashingOptions.Algorithm,
                Validate  = false
            };
        }
示例#2
0
        public LazyLoadingReadOnlyStream(
            DownloadInternalAsync downloadInternalFunc,
            GetPropertiesAsync getPropertiesFunc,
            bool allowModifications,
            long initialLenght,
            long position  = 0,
            int?bufferSize = default)
        {
            _downloadInternalFunc      = downloadInternalFunc;
            _getPropertiesInternalFunc = getPropertiesFunc;
            _position   = position;
            _bufferSize = bufferSize ?? Constants.DefaultStreamingDownloadSize;
            _buffer     = ArrayPool <byte> .Shared.Rent(_bufferSize);

            _allowBlobModifications = allowModifications;
            _bufferPosition         = 0;
            _bufferLength           = 0;
            _length            = initialLenght;
            _bufferInvalidated = false;
        }
示例#3
0
        // TODO #27253
        ///// <summary>
        ///// Hashing options to use with <see cref="_downloadInternalFunc"/>.
        ///// </summary>
        //private readonly DownloadTransactionalHashingOptions _hashingOptions;

        public LazyLoadingReadOnlyStream(
            DownloadInternalAsync downloadInternalFunc,
            GetPropertiesAsync getPropertiesFunc,
            // TODO #27253
            //DownloadTransactionalHashingOptions hashingOptions,
            bool allowModifications,
            long initialLenght,
            long position  = 0,
            int?bufferSize = default,
            PredictEncryptedRangeAdjustment rangePredictionFunc = default)
        {
            _downloadInternalFunc            = downloadInternalFunc;
            _getPropertiesInternalFunc       = getPropertiesFunc;
            _predictEncryptedRangeAdjustment = rangePredictionFunc ?? (range => range);
            _position   = position;
            _bufferSize = bufferSize ?? Constants.DefaultStreamingDownloadSize;
            _buffer     = ArrayPool <byte> .Shared.Rent(_bufferSize);

            _allowBlobModifications = allowModifications;
            _bufferPosition         = 0;
            _bufferLength           = 0;
            _length            = initialLenght;
            _bufferInvalidated = false;

            // TODO #27253
            // the caller to this stream cannot defer validation, as they cannot access a returned hash
            //if (!(hashingOptions?.Validate ?? true))
            //{
            //    throw Errors.CannotDeferTransactionalHashVerification();
            //}
            // we defer hash validation on download calls to validate in-place with our existing buffer
            //_hashingOptions = hashingOptions == default
            //    ? default
            //    : new DownloadTransactionalHashingOptions
            //    {
            //        Algorithm = hashingOptions.Algorithm,
            //        Validate = false
            //    };
        }