匯出 (0) 列印
全部展開
本主題尚未接受評分 - 為這個主題評分

CloudPageBlob.WritePages 方法 (Stream, Int64)

Writes pages to a page blob.

命名空間: Microsoft.WindowsAzure.StorageClient
組件: Microsoft.WindowsAzure.StorageClient (在 microsoft.windowsazure.storageclient.dll 中)
'用途
Dim instance As CloudPageBlob
Dim pageData As Stream
Dim startOffset As Long

instance.WritePages(pageData, startOffset)
public void WritePages (
	Stream pageData,
	long startOffset
)
public void WritePages (
	Stream pageData, 
	long startOffset
)
public function WritePages (
	pageData : Stream, 
	startOffset : long
)

參數

pageData

A stream providing the page data.

startOffset

The offset at which to begin writing, in bytes. The offset must be a multiple of 512.

The following code example creates a page blob, writes some pages to it, and prints out the page ranges to the console.

static void WriteToPageBlob(Uri blobEndpoint, string accountName, string accountKey)
{
    //Create service client for credentialed access to the Blob service.
    CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(accountName, accountKey));

    // create container if it does not exist
    CloudBlobContainer cloudContainer = blobClient.GetContainerReference("mypageblobs");
    cloudContainer.CreateIfNotExist();

    //Get a reference to the page blob that will be created.
    CloudPageBlob pageBlob = cloudContainer.GetPageBlobReference("apageblob");

    //Generate some data to write.  
    byte[] data = new byte[1024];
    Random rnd = new Random();
    rnd.NextBytes(data);

    //Create a 100 MB page blob.
    pageBlob.Create(100 * 1024 * 1024);

    //Write two sets of pages. Note that you can write 4 MB per call to WritePages().
    pageBlob.WritePages(new MemoryStream(data), 0);
    pageBlob.WritePages(new MemoryStream(data), 4096);

    //Populate the page blob's attributes.
    pageBlob.FetchAttributes();
    Console.WriteLine("Blob length = {0}", pageBlob.Properties.Length);

    //Print out the current range of pages.
    PrintPageRanges("Before write to 10240:", pageBlob);

    //Write another page.
    pageBlob.WritePages(new MemoryStream(data), 10240);

    //Print out the new range of pages.
    PrintPageRanges("After write to 10240:", pageBlob);

    //Clear a page.
    pageBlob.ClearPages(4096, 1024);

    //Print out the new range of pages.
    PrintPageRanges("After clearing page at 4096:", pageBlob);

    //Delete the page blob.
    pageBlob.Delete();
}

static void PrintPageRanges(string msg, CloudPageBlob cloudBlob)
{
    //Write out the page ranges for the page blob.
    IEnumerable<PageRange> ranges = cloudBlob.GetPageRanges();
            
    Console.Write("{0}:<", msg);
            
    foreach (PageRange range in ranges)
    {
        Console.Write(" [{0}-{1}] ", range.StartOffset, range.EndOffset);
    }

    Console.WriteLine(">");
}


The WritePages method writes a range of pages to a page blob. This method can only be called on an existing page blob; it cannot be called to create a new page blob.

Each range of pages submitted with WritePages may be up to 4 MB in size. The start and end range of the page must be aligned with 512-byte boundaries.

The Blob service serializes concurrent writes to overlapping pages sequentially: the last page processed by the service determines the blob's content. Therefore, to ensure the integrity of the blob's content, you should handle writes to overlapping pages using one or more of the following approaches:

  • You can check the value of the blob's LastModifiedUtc property for each successful call to WritePages. The order of responses returned from the Blob service does not necessarily correspond to the order in which they were executed by the service. But the last modified time always indicates the order in which the service processed the requests.

  • You can perform updates conditionally based on the blob's ETag or last modified time using optimistic concurrency. This approach works well if the number of concurrent writes is relatively low. Specify an access condition using the AccessCondition property of the BlobRequestOptions class.

  • You can acquire a least on the blob to lock it against other writes. See the Lease method of the BlobRequest class.


任何這個類型的公用靜態 (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。 並非所有的執行個體成員都是安全執行緒。

開發平台

Windows XP Home Edition, Windows XP Professional, Windows Server 2003、Windows Server 2008 和 Windows 2000

目標平台

本文對您有任何幫助嗎?
(剩餘 1500 個字元)
感謝您提供意見

社群新增項目

Microsoft 正展開一份線上問卷調查,了解您對於 MSDN 網站的看法。 如果您選擇參加,您離開 MSDN 網站時即會顯示線上問卷調查。

您是否想要參加?
顯示:
© 2014 Microsoft. 著作權所有,並保留一切權利。