Example #1
0
        async Task IFileBackend.ReadFileAsync(
            object context,
            string id,
            Stream stream,
            long from,
            long to,
            long totalLength,
            CancellationToken cancellationToken)
        {
            var config = context as Context;

            using (var response = await config.S3.GetObjectAsync(new GetObjectRequest
            {
                BucketName = config.BucketName,
                Key = id,
                ByteRange = totalLength == -1
                    ? null
                    : new ByteRange(from, to)
            }, cancellationToken))
            {
                Console.WriteLine($"ReadFileAsync: id:{id} response.ContentLength: {response.ContentLength}");

                //using (var bufferedResponse = new BufferedStream(response.ResponseStream))
                using (var responseStream = new StreamRequestWrapper(
                           response.ResponseStream, response.ContentLength, Logger
                           ))
                    //await CopyBytesAsync(responseStream, stream, response.ContentLength, cancellationToken);
                    await response.ResponseStream.CopyToAsync(stream, 81920, cancellationToken);
                await stream.FlushAsync();
            }
        }
Example #2
0
        public async Task <string> PutChunk(
            string id,
            string uploadKey,
            string chunkKey,
            string sequentialState,
            int chunkIndex,
            int totalChunks,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Logger.LogDebug($"SequentialState: {sequentialState}");

            var  range  = ContentRangeHeaderValue.Parse(Request.Headers["X-Content-Range"]);
            long length = (long)range.To - (long)range.From + 1;

            using (var requestStream = new StreamRequestWrapper(Request.Body, length))
                return(await backend.ChunkedUploadChunkAsync(
                           context,
                           id,
                           uploadKey,
                           chunkKey,
                           chunkIndex,
                           totalChunks,
                           sequentialState,
                           (long)range.From,
                           (long)range.To,
                           (long)range.Length,
                           requestStream,
                           cancellationToken
                           ));
        }
Example #3
0
        async Task <string> IFileBackend.ChunkedUploadChunkAsync(
            object context,
            string id,
            string uploadKey,
            string chunkKey,
            int chunkIndex,
            int totalChunks,
            string sequentialState,
            long from,
            long to,
            long totalLength,
            Stream stream,
            CancellationToken cancellationToken
            )
        {
            var config = context as Context;

            var state   = new SequentialState(sequentialState);
            var digests = PrepareDigests(config, state, isFirstChunk: chunkIndex == 0);

            using (var encryptor = new ChunkEncryptorStreamReader(
                       stream,
                       config.CryptographyAlgorithm,
                       from,
                       to,
                       totalLength,
                       digests,
                       state.IV(),
                       Logger
                       ))
                using (var wrapper = new StreamRequestWrapper(encryptor, encryptor.Length, Logger))
                {
                    state.NextDriverState = await config.NextDriver.ChunkedUploadChunkAsync(
                        config.NextDriverContext, id, uploadKey, chunkKey, chunkIndex, totalChunks,
                        state.NextDriverState,
                        from, to, totalLength, wrapper,
                        cancellationToken
                        );

                    state.IVBase64 = Convert.ToBase64String(encryptor.NextIV());

                    return(state.ToString());
                }
        }