[BUG] A open stream with BlobOpenReadOptions(true) says that stream.canSeek true but says cannot seek on end
See original GitHub issueDescribe the bug A open stream with BlobOpenReadOptions(true) says that stream.canSeek true but says cannot seek on end. In my case, the stream is handed over to external libraries and on this point there is no possibility to check which seek is used.
Expected behavior As the error message says that ‘Cannot Seek with SeekOrigin.End on a growing blob or file. Call Stream.Seek(Stream.Length, SeekOrigin.Begin) to get to the end of known data.’ The value of stream.canSeek should be false or Seek(0, SeekOrigin.End) should work like Seek(Stream.Lenght, SeekOrigin.Begin)
Actual behavior (include Exception or Stack Trace) System.ArgumentException: ‘Cannot Seek with SeekOrigin.End on a growing blob or file. Call Stream.Seek(Stream.Length, SeekOrigin.Begin) to get to the end of known data. Arg_ParamName_Name’
To Reproduce
[SkippableFact]
public async void TestDecompressErrorForZip()
{
string connectionString = Constants.ConnectionStringTestBlobStorage;
string fileName = $"anyfile{Guid.NewGuid()}.zip";
BlobContainerClient blobContainerClient= new BlobContainerClient(connectionString, Constants.TestContainerName.Value);
BlobClient blob = blobContainerClient.GetBlobClient(fileName);
await blob.UploadAsync("anyfile.zip");
using (var fileStreamErr = await blob.OpenReadAsync(new BlobOpenReadOptions(false)))
{
if (fileStreamErr.CanSeek)
{
fileStreamErr.ReadByte();
fileStreamErr.Seek(0, SeekOrigin.Begin);
fileStreamErr.Seek(0, SeekOrigin.End);
}
}
using (var fileStreamErr = await blob.OpenReadAsync(new BlobOpenReadOptions(true)))
{
if (fileStreamErr.CanSeek)
{
fileStreamErr.ReadByte();
fileStreamErr.Seek(0, SeekOrigin.Begin);
// This should not fail, because CanSeek is true
fileStreamErr.Seek(0, SeekOrigin.End);
}
}
}
Environment:
- Azure.Storage.Blobs 12.9.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Unfortunately, changing this behavior may be considered a breaking change, which we are not allowed to make. Other users may have taken a dependency on this behavior.
You anyone is expect a exception to be thrown when he calls a method which says “you are not allowed to do this”. I understand your point of backward compatibility but think it’s only academical in this case because you remove a “fobiden” sign. Every one who expect the exception won’t call this method.