public void StreamWithOffsets()
        {
            int len  = byte.MaxValue + 1;
            var data = new byte[len];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)i;
            }
            var dataStream = new MemoryStream(data);

            var    privateContainerName = "test-" + Guid.NewGuid().ToString("N");
            string etag;

            BlobStorage.PutBlobStream(privateContainerName, "testa", dataStream, true, out etag);
            Assert.AreEqual(etag, BlobStorage.GetBlobEtag(privateContainerName, "testa"));

            string etag1;
            var    res1 = BlobStorage.GetBlobStream(privateContainerName, "testa", out etag1);

            Assert.IsTrue(res1.HasValue);
            Assert.AreEqual(etag, etag1);
            var res1a = ((MemoryStream)res1).ToArray();

            Assert.AreEqual(data.Length, res1a.Length);
            for (int i = 0; i < res1a.Length; i++)
            {
                Assert.AreEqual(data[i], res1a[i]);
            }

            string etag2;
            var    res2 = BlobStorage.GetBlobOffsetStream(privateContainerName, "testa", 0, len / 2, out etag2);

            Assert.IsTrue(res2.HasValue);
            Assert.AreEqual(etag, etag2);
            var res2a = ((MemoryStream)res2).ToArray();

            Assert.AreEqual(len / 2, res2a.Length);
            for (int i = 0; i < res2a.Length; i++)
            {
                Assert.AreEqual(data[i], res2a[i]);
            }

            string etag3;
            var    res3 = BlobStorage.GetBlobOffsetStream(privateContainerName, "testa", len / 2, len - len / 2, out etag3);

            Assert.IsTrue(res3.HasValue);
            Assert.AreEqual(etag, etag3);
            var res3a = ((MemoryStream)res3).ToArray();

            Assert.AreEqual(len - len / 2, res3a.Length);
            for (int i = 0; i < res3a.Length; i++)
            {
                Assert.AreEqual(data[i + len / 2], res3a[i]);
            }

            // Test too long length > actual blob length
            string etag4;
            var    res4 = BlobStorage.GetBlobOffsetStream(privateContainerName, "testa", len / 2, 3 * len, out etag4);

            Assert.IsTrue(res4.HasValue);
            Assert.AreEqual(etag, etag4);
            var res4a = ((MemoryStream)res4).ToArray();

            Assert.AreEqual(len - len / 2, res4a.Length);
            for (int i = 0; i < res4a.Length; i++)
            {
                Assert.AreEqual(data[i + len / 2], res4a[i]);
            }
        }
 public static bool PutBlobStream(this IBlobStorageProvider provider, IBlobLocation location, Stream stream, bool overwrite)
 {
     return(provider.PutBlobStream(location.ContainerName, location.Path, stream, overwrite));
 }
 /// <summary>Push the blob only if etag is matching the etag of the blob in BlobStorage</summary>
 public static bool PutBlobStream(this IBlobStorageProvider provider, IBlobLocationAndType <Stream> location, Stream stream, string etag)
 {
     return(provider.PutBlobStream(location.ContainerName, location.Path, stream, etag));
 }
 public static void PutBlobStream(this IBlobStorageProvider provider, IBlobLocation location, Stream stream)
 {
     provider.PutBlobStream(location.ContainerName, location.Path, stream);
 }