Kiriox
Kiriox
Explore posts from servers
CC#
Created by Kiriox on 12/22/2024 in #help
Downloading large file
Hello, I need to be able to download files up to 400Mb asynchronously and track the download in a progress bar. I have this code except that it doesn't work totally, on 50Mb files it's fine but 130Mb it crashes and moreover it takes a while before starting the download. So I wanted to know if this was the right method and if it was possible to optimize it?
c#
int DefaultCopyBufferSize = 81920;
string destinationPath = Path.GetTempFileName();
using var client = new HttpClient();

using var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
using var source = await response.Content.ReadAsStreamAsync();
using var destination = File.OpenWrite(destinationPath);

int bytesRead;
var buffer = ArrayPool<byte>.Shared.Rent(DefaultCopyBufferSize);
var memory = buffer.AsMemory();

while ((bytesRead = await source.ReadAsync(memory)) > 0)
{
await destination.WriteAsync(memory[..bytesRead]);
progress.Increment(bytesRead);
}
c#
int DefaultCopyBufferSize = 81920;
string destinationPath = Path.GetTempFileName();
using var client = new HttpClient();

using var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
using var source = await response.Content.ReadAsStreamAsync();
using var destination = File.OpenWrite(destinationPath);

int bytesRead;
var buffer = ArrayPool<byte>.Shared.Rent(DefaultCopyBufferSize);
var memory = buffer.AsMemory();

while ((bytesRead = await source.ReadAsync(memory)) > 0)
{
await destination.WriteAsync(memory[..bytesRead]);
progress.Increment(bytesRead);
}
69 replies
CC#
Created by Kiriox on 12/12/2024 in #help
FolderBrowserDialog on .net core
Hello, is there a native alternative to FolderBrowserDialog in .net core 9 that is compatible with all platforms?
25 replies
CC#
Created by Kiriox on 12/8/2024 in #help
Most optimized download system
Hi, I need to download a file separated into different chunks (between 100 and 400 mb each) from a server and make it as fast as possible. Except that I'm a bit confused, I've seen that there are lots of different methods for downloading files, with the added bonus of possibly downloading more than one at the same time. I was wondering if you had any advice on how to go about it? The code I'm currently using:
ProgressTask progress = ctx.AddTask("Downloading chunks", true, fileInfos.size);

AnsiConsole.MarkupLine($"[gray]LOG: [/] Started download of [blue]{fileInfos.chunksCount}[/] chunks");
for (int i = 1; i <= fileInfos.chunksCount; i++)
{
await DownloadChunk(fileInfos.host, fileInfos.wd, fileInfos.id, i, fileInfos.chunkSizes[i - 1], progress);
}

AnsiConsole.MarkupLine("[yellow]Assembling chunks...[/]");
CombineChunks(tempDir, Path.Combine(downloadDir, fileInfos.filename), fileInfos.id);
ProgressTask progress = ctx.AddTask("Downloading chunks", true, fileInfos.size);

AnsiConsole.MarkupLine($"[gray]LOG: [/] Started download of [blue]{fileInfos.chunksCount}[/] chunks");
for (int i = 1; i <= fileInfos.chunksCount; i++)
{
await DownloadChunk(fileInfos.host, fileInfos.wd, fileInfos.id, i, fileInfos.chunkSizes[i - 1], progress);
}

AnsiConsole.MarkupLine("[yellow]Assembling chunks...[/]");
CombineChunks(tempDir, Path.Combine(downloadDir, fileInfos.filename), fileInfos.id);
DownloadChunk:
using (var client = new WebClient())
{
long previousBytesReceived = 0;
client.DownloadProgressChanged += (sender, e) =>
{
progress.Increment(e.BytesReceived - previousBytesReceived);
previousBytesReceived = e.BytesReceived;
};
client.DownloadFileCompleted += (sender, e) => AnsiConsole.MarkupLine($"[gray]LOG: [/]Finished download of chunk [green]{chunkNumber}[/]");
await client.DownloadFileTaskAsync(new Uri(url), destinationPath);
}
using (var client = new WebClient())
{
long previousBytesReceived = 0;
client.DownloadProgressChanged += (sender, e) =>
{
progress.Increment(e.BytesReceived - previousBytesReceived);
previousBytesReceived = e.BytesReceived;
};
client.DownloadFileCompleted += (sender, e) => AnsiConsole.MarkupLine($"[gray]LOG: [/]Finished download of chunk [green]{chunkNumber}[/]");
await client.DownloadFileTaskAsync(new Uri(url), destinationPath);
}
66 replies
DIAdiscord.js - Imagine an app
Created by Kiriox on 7/31/2024 in #djs-questions
Impossible to timeout members from GuildMembersManager object
Hello, in my script I tried to timeout a member from the GuildMembersManager object as it is possible with kick or ban but it gives me the error guild.members.timeout is not a function yet there is this pr that has been merge which seems to do what I want. What can I do? https://github.com/discordjs/discord.js/pull/7104
8 replies
DIAdiscord.js - Imagine an app
Created by Kiriox on 7/22/2024 in #djs-questions
guildMemberRemove event don't work
Hello, the guildMemberRemove event does not trigger when my second account which is the server while in the same circumstances guildMemberAdd works, what can I do?
6 replies
DIAdiscord.js - Imagine an app
Created by Kiriox on 6/1/2024 in #djs-questions
Discord.js RPC Extension work ?
I found this extension https://github.com/discordjs/RPC/ for discord.js which allows the use of rpc, which leads me to 2 questions: the last update of the project was 3 years ago and the documentation is no longer available, does it still work. And secondly, can I use it to activate the rpc on people who connect to my web page?
4 replies
DIAdiscord.js - Imagine an app
Created by Kiriox on 10/15/2023 in #djs-voice
Recover audio and mute user
Hello I would like to be able to record audio in a voice room (and if possible only record what a user defined by id says) I have not found a clear explanation for version 14 of discord.js, could Can you explain to me how I can achieve my goal?
16 replies