Пример #1
0
 public override long Seek(long offset, SeekOrigin origin)
 {
     return(_inner.Seek(offset, origin));
 }
Пример #2
0
        static async Task BlobAsync()
        {
            try
            {
                CloudStorageAccount sa = CloudStorageAccount.Parse(connectionString);
                CloudBlobClient     bc = sa.CreateCloudBlobClient();

                const string       CON_NAME = "smart-blob-container";
                CloudBlobContainer con      = bc.GetContainerReference(CON_NAME);
                bool rr = await con.CreateIfNotExistsAsync();

                const string  blobName = "my.txt";
                CloudPageBlob blob     = con.GetPageBlobReference(blobName);

                bool del = await blob.DeleteIfExistsAsync();

                await blob.CreateAsync(64 *1024, AccessCondition.GenerateIfNotExistsCondition(), new BlobRequestOptions(), new OperationContext());

                using (CloudBlobStream blobStream = await blob.OpenWriteAsync(null, AccessCondition.GenerateEmptyCondition(), new BlobRequestOptions(), new OperationContext()))
                {
                    byte[] sector = new byte[512];
                    for (int ii = 0; ii < sector.Length; ++ii)
                    {
                        sector[ii] = (byte)(ii % 26 + 'A');
                    }
                    MemoryStream mm = new MemoryStream(sector);
                    //byte[] buffer = Encoding.UTF8.GetBytes("zzz宏发科技恢复健康哈尔月UI风雅颂的法尔加zzz----");
                    //await blobStream.WriteAsync(buffer, 0, buffer.Length);
                    //await blobStream.WriteAsync(sector, 0, sector.Length - buffer.Length);
                    await blobStream.WriteAsync(sector, 0, sector.Length);

                    if (blobStream.CanSeek)
                    {
                        blobStream.Seek(1024, System.IO.SeekOrigin.Begin);
                    }

                    //buffer = Encoding.UTF8.GetBytes("this is some test");
                    //await blobStream.WriteAsync(buffer, 0, buffer.Length);
                    //await blobStream.WriteAsync(sector, 0, sector.Length - buffer.Length);
                    await blobStream.WriteAsync(sector, 0, sector.Length);

                    await blobStream.FlushAsync();
                }


                using (Stream blobStream = await blob.OpenReadAsync())
                {
                    byte[] buffer = new byte[2048];

                    const int firstReadCount = 8;
                    int       rc             = await blobStream.ReadAsync(buffer, 0, firstReadCount);

                    if (blobStream.CanSeek)
                    {
                        blobStream.Seek(rc, SeekOrigin.Begin);
                    }
                    rc = await blobStream.ReadAsync(buffer, 8, buffer.Length - firstReadCount);

                    string text = Encoding.UTF8.GetString(buffer);
                    Console.WriteLine(text);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex}");
            }
        }