示例#1
0
 /// <summary> Write a buffer of bytes to the store. </summary>
 public static async Task <WrittenBlob> WriteAsync(
     this IWriteOnlyStore store,
     byte[] buffer,
     int offset,
     int count,
     CancellationToken cancel)
 {
     using (var writer = store.StartWriting())
         return(await writer.WriteAndCommitAsync(buffer, offset, count, cancel).ConfigureAwait(false));
 }
示例#2
0
        private static async Task <WrittenBlob> ImportBlobUnchecked(this IWriteOnlyStore store, IReadBlobRef srcBlob, CancellationToken cancel)
        {
            using (var writer = store.StartWriting())
            {
                using (var reader = await srcBlob.OpenAsync(cancel).ConfigureAwait(false))
                {
                    await writer.WriteAsync(reader.ReadAsync, null, cancel).ConfigureAwait(false);
                }

                return(await writer.CommitAsync(cancel).ConfigureAwait(false));
            }
        }
示例#3
0
        /// <summary> Write a stream to a store. </summary>
        /// <remarks> Reads forward from the current position of the stream. </remarks>
        public static async Task <WrittenBlob> WriteAsync(
            this IWriteOnlyStore store,
            Stream stream,
            int bufferSize,
            CancellationToken cancel)
        {
            // Don't allocate memory we don't need.
            if (stream.CanSeek && stream.Length < bufferSize)
            {
                bufferSize = (int)stream.Length;
            }

            using (var writer = store.StartWriting())
            {
                var buffer = new byte[bufferSize];
                await WriteAsync(writer, stream, buffer, null, true, cancel).ConfigureAwait(false);

                return(await writer.CommitAsync(cancel).ConfigureAwait(false));
            }
        }