Skip to content

Commit 8557c64

Browse files
authored
Merge pull request #100 from garath/mistucke/use-released-azure-storage-blobs
Update to released Azure Storage SDK
2 parents 570a1d7 + d4af3cb commit 8557c64

File tree

2 files changed

+20
-56
lines changed

2 files changed

+20
-56
lines changed

src/SourceBrowser/src/SourceIndexServer/Models/AzureBlobFileSystem.cs

+19-55
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,18 @@
1-
using System;
1+
using Azure.Storage.Blobs;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
5-
using System.Reflection;
6-
using Azure.Core.Pipeline;
7-
using Azure.Storage;
8-
using Azure.Storage.Blobs;
9-
using Azure.Storage.Blobs.Models;
106

117
namespace Microsoft.SourceBrowser.SourceIndexServer.Models
128
{
139
public class AzureBlobFileSystem : IFileSystem
1410
{
15-
private class AnonContainerClient : BlobContainerClient
16-
{
17-
public override Uri Uri { get; }
18-
protected override HttpPipeline Pipeline { get; }
19-
20-
public AnonContainerClient(string uri)
21-
{
22-
Uri = new Uri(uri);
23-
Pipeline = HttpPipelineBuilder.Build(new BlobClientOptions());
24-
}
25-
26-
public override BlobClient GetBlobClient(string blobName)
27-
{
28-
return (BlobClient)typeof(BlobClient).GetTypeInfo().DeclaredConstructors.Single(ctor => ctor.ToString() == "Void .ctor(System.Uri, Azure.Core.Pipeline.HttpPipeline)").Invoke(new object[] { AppendToPath(this.Uri, blobName), this.Pipeline });
29-
}
30-
31-
private static Uri AppendToPath(Uri uri, string segment)
32-
{
33-
UriBuilder uriBuilder = new UriBuilder(uri);
34-
string path = uriBuilder.Path;
35-
uriBuilder.Path = uriBuilder.Path + (path.Length == 0 || path[path.Length - 1] != '/' ? "/" : "") + segment;
36-
return uriBuilder.Uri;
37-
}
38-
}
39-
4011
private readonly BlobContainerClient container;
12+
4113
public AzureBlobFileSystem(string uri)
4214
{
43-
container = new AnonContainerClient(uri);
15+
container = new BlobContainerClient(new Uri(uri));
4416
}
4517

4618
public bool DirectoryExists(string name)
@@ -57,45 +29,37 @@ public IEnumerable<string> ListFiles(string dirName)
5729
dirName += "/";
5830
}
5931

60-
return container.GetBlobsByHierarchy("/", new GetBlobsOptions
61-
{
62-
Prefix = dirName,
63-
}).Select(res => res.Value).Where(item => item.IsBlob).Select(item => item.Blob.Name).ToList();
32+
return container.GetBlobsByHierarchy(prefix: dirName)
33+
.Where(item => item.IsBlob)
34+
.Select(item => item.Blob.Name)
35+
.ToList();
6436
}
6537

6638
public bool FileExists(string name)
6739
{
6840
name = name.ToLowerInvariant();
69-
var blob = container.GetBlobClient(name);
70-
try
71-
{
72-
blob.GetProperties();
73-
return true;
74-
}
75-
catch (StorageRequestFailedException ex) when (string.Equals(ex.ErrorCode, "BlobNotFound"))
76-
{
77-
return false;
78-
}
41+
BlobClient blob = container.GetBlobClient(name);
42+
43+
return blob.Exists();
7944
}
8045

8146
public Stream OpenSequentialReadStream(string name)
8247
{
8348
name = name.ToLowerInvariant();
84-
var blob = container.GetBlobClient(name);
85-
return blob.Download().Value.Content;
49+
BlobClient blob = container.GetBlobClient(name);
50+
return blob.OpenRead();
8651
}
8752

8853
public IEnumerable<string> ReadLines(string name)
8954
{
9055
name = name.ToLowerInvariant();
91-
var blob = container.GetBlobClient(name);
92-
using (var stream = blob.Download().Value.Content)
93-
using (var reader = new StreamReader(stream))
56+
BlobClient blob = container.GetBlobClient(name);
57+
using Stream stream = blob.OpenRead();
58+
using StreamReader reader = new (stream);
59+
60+
while (!reader.EndOfStream)
9461
{
95-
while (!reader.EndOfStream)
96-
{
97-
yield return reader.ReadLine();
98-
}
62+
yield return reader.ReadLine();
9963
}
10064
}
10165
}

src/SourceBrowser/src/SourceIndexServer/SourceIndexServer.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Azure.Storage.Blobs" Version="12.0.0-preview.3" />
11+
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)