How to enable seeking in Azure Blob stream

2019-09-04 04:53发布

问题:

I have a BlobStream that is created from the method OpenWriter.

var blob = CloudContainer.GetBlobReference(name));
if (blob == null)
{
   return null;
}

return blob.OpenWrite();

Using this stream i would like to seek or set the position, but each time i do this i get a NotSupportedException. After doing some research i found that the canSeek is set to false, which causes this problem. But, the CanSeek is false only if the length is unknown. But the length is known when i run the debugger.

Why is CanSeek false? How can i make it set to true?

回答1:

You can seek within a page blob - there is explicit support for it in BlobWriteStreamBase class.

I think you could also read & write to specified parts of a Block blob using HTTP Range headers, which would be effectively the same thing as seeking. But I think you'd have to implement that yourself.