Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 9952f2f

Browse files
committed
Addressing code review comments by using Streams instead of ing the contents into a string.
1 parent 439c4e6 commit 9952f2f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/Microsoft.DotNet.Cli.Utils/RuntimeConfig.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ public class RuntimeConfig
1313
public RuntimeConfigFramework Framework { get; }
1414

1515
public RuntimeConfig(string runtimeConfigPath)
16-
{
17-
var runtimeConfigJson = OpenRuntimeConfig(runtimeConfigPath);
18-
19-
Framework = ParseFramework(runtimeConfigJson);
20-
21-
IsPortable = Framework != null;
16+
{
17+
JObject runtimeConfigJson;
18+
using (var streamReader = new StreamReader(new FileStream(runtimeConfigPath, FileMode.Open)))
19+
{
20+
runtimeConfigJson = OpenRuntimeConfig(streamReader);
21+
}
22+
23+
Framework = ParseFramework(runtimeConfigJson);
24+
25+
IsPortable = Framework != null;
2226
}
2327

2428
public static bool IsApplicationPortable(string entryAssemblyPath)
@@ -32,9 +36,9 @@ public static bool IsApplicationPortable(string entryAssemblyPath)
3236
return false;
3337
}
3438

35-
private JObject OpenRuntimeConfig(string runtimeConfigPath)
39+
private JObject OpenRuntimeConfig(StreamReader streamReader)
3640
{
37-
var reader = new JsonTextReader(new StringReader(File.ReadAllText(runtimeConfigPath)));
41+
var reader = new JsonTextReader(streamReader);
3842

3943
return JObject.Load(reader);
4044
}

src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,30 @@ public static IEnumerable<string> QueryNuGet(string match)
5454
{
5555
var httpClient = new HttpClient();
5656

57-
string result;
57+
Stream result;
5858

5959
try
6060
{
6161
var cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(10));
6262
var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token)
6363
.Result;
6464

65-
result = response.Content.ReadAsStringAsync().Result;
65+
result = response.Content.ReadAsStreamAsync().Result;
6666
}
6767
catch (Exception)
6868
{
6969
yield break;
7070
}
7171

72-
using (var reader = new JsonTextReader(new StringReader(result)))
72+
JObject json;
73+
using (var reader = new JsonTextReader(new StreamReader(result)))
7374
{
74-
var json = JObject.Load(reader);
75+
json = JObject.Load(reader);
76+
}
7577

76-
foreach (var id in json["data"])
77-
{
78-
yield return id["id"].Value<string>();
79-
}
78+
foreach (var id in json["data"])
79+
{
80+
yield return id["id"].Value<string>();
8081
}
8182
}
8283
}

0 commit comments

Comments
 (0)