DownloadFileAsync: don't use stream.Position if !CanSeek

This commit is contained in:
Wizou 2024-02-01 21:24:49 +01:00
parent 6f3c8732ec
commit 0ad7d696a5
3 changed files with 4 additions and 4 deletions

2
.github/dev.yml vendored
View file

@ -1,7 +1,7 @@
pr: none
trigger: [ master ]
name: 3.6.5-dev.$(Rev:r)
name: 3.6.6-dev.$(Rev:r)
pool:
vmImage: ubuntu-latest

2
FAQ.md
View file

@ -235,7 +235,7 @@ In particular, it will detect and handle automatically and properly the various
* 2FA password required (your Config needs to provide "password")
* Email registration procedure required (your Config needs to provide "email", "email_verification_code")
* Account registration/sign-up required (your Config needs to provide "first_name", "last_name")
* Request to resend the verification code through alternate ways like SMS (if your Config answer an empty "verification_code" initially)
* Request to resend the verification code through alternate ways (if your Config answer an empty "verification_code" initially)
* Transient failures, slowness to respond, wrong code/password, checks for encryption key safety, etc..
Contrary to TLSharp, WTelegramClient supports MTProto v2.0 (more secured), transport obfuscation, protocol security checks, MTProto [Proxy](EXAMPLES.md#proxy), real-time updates, multiple DC connections, API documentation in Intellisense...

View file

@ -317,7 +317,7 @@ namespace WTelegram
var client = dc_id == 0 ? this : await GetClientForDC(dc_id, true);
using var writeSem = new SemaphoreSlim(1);
bool canSeek = outputStream.CanSeek;
long streamStartPos = outputStream.Position;
long streamStartPos = canSeek ? outputStream.Position : 0;
long fileOffset = 0, maxOffsetSeen = 0;
long transmitted = 0;
var tasks = new Dictionary<long, Task>();
@ -373,7 +373,7 @@ namespace WTelegram
await writeSem.WaitAsync();
try
{
if (streamStartPos + offset != outputStream.Position) // if we're about to write out of order
if (canSeek && streamStartPos + offset != outputStream.Position) // if we're about to write out of order
{
await outputStream.FlushAsync(); // async flush, otherwise Seek would do a sync flush
outputStream.Seek(streamStartPos + offset, SeekOrigin.Begin);