最後活躍 1704276890

Program.cs 原始檔案
1using System.IO.Compression;
2using Newtonsoft.Json;
3
4public class Program
5{
6 public static async Task Main(string[] args)
7 {
8 var address =
9 @"qb";
10 var flPath = Path.Combine(Directory.GetCurrentDirectory(), "files.txt");
11 var gzPath = Path.Combine(Directory.GetCurrentDirectory(), "files.txt.gz");
12 var httpClient = new HttpClient();
13 var response = await httpClient.GetAsync(address);
14 var content = await response.Content.ReadAsStringAsync();
15 var serverResponse = JsonConvert.DeserializeObject<ServerResponse>(content)!;
16 var files = serverResponse.Files!.Select(x => x.Key).ToArray();
17
18 // save files to files.txt and files.txt.gz
19 await File.WriteAllLinesAsync(flPath, files);
20 Console.WriteLine($"Files saved to {flPath}");
21
22 // save files to files.txt.gz
23 await using var fileStream = File.Create(gzPath);
24 await using var gzipStream = new GZipStream(fileStream, CompressionMode.Compress);
25 await using var writer = new StreamWriter(gzipStream);
26 foreach (var file in files)
27 {
28 await writer.WriteLineAsync(file);
29 }
30
31 Console.WriteLine($"Files saved to {gzPath}");
32
33 // Read the gz file back:
34 //await ReadBack(gzPath);
35 }
36
37 private static async Task ReadBack(string gzFile)
38 {
39 await using var fileStream = File.OpenRead(gzFile);
40 await using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress);
41 using var reader = new StreamReader(gzipStream);
42 var linesArray = (await reader.ReadToEndAsync()).Split(Environment.NewLine);
43 foreach (var line in linesArray)
44 {
45 Console.WriteLine(line);
46 }
47 }
48}
49
50public class ServerResponse
51{
52 [JsonProperty("cr:itemType")]
53 public string? ItemType { get; set; }
54
55 [JsonProperty("cr:files")]
56 public Dictionary<string, string>? Files { get; set; }
57}