You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tg media download fails on Windows: EPERM ftruncate (truncating an append handle) #233
Every tg media download on Windows fails, for photos and for documents:
$ tg media download --chat -1001420000565 --id 802
{
"success": false,
"error": {
"code": "TELEGRAM_ERROR",
"message": "Failed to download media: EPERM: operation not permitted, ftruncate",
"retryable": false
}
}
The partial file is created (0 bytes, .photo.jpg.part), then the download stops before the first upload.getFile call — tg status shows no upload.getFile traffic and no FLOOD_WAIT.
Tried and failed the same way:
a photo (802), a document (355), a video (487);
--out <dir>, --thumb, --overwrite;
repeated runs (the stale .part is not the cause).
Environment
Windows 11 x64 (10.0.26300), release binary tg-windows-x64.exe from v0.15.1
tg --version → 0.15.1, the bundled runtime reports mtcute on Bun/1.4.3, initConnectionappVersion 0.32.6
account signed in by QR, readOnly: true, no daemon running
cache DB and media cache on a normal NTFS volume under %USERPROFILE%; the same directory accepts writes from PowerShell, Node (fs.ftruncateSync) and .NET (FileStream.SetLength), so it is not a file-system or ACL problem
On Windows an "a" handle is opened with FILE_APPEND_DATA and without FILE_WRITE_DATA, and SetEndOfFile on such a handle fails with EPERM. offset is 0 here, so the truncate is a no-op on POSIX and fatal on Windows. The .part file is created by the open and stays 0 bytes, which matches what I see on disk.
Suggested fix
Do not truncate through the append handle. Any of these should do it:
open with "r+" (create first when missing) and pass { flags } only for appends, or
truncate by path before opening for append: await truncate(part, offset) / ftruncateSync, or
when offset === 0, open with "w" instead of "a".
Workaround I use
The session database is a plain mtcute SQLite file, so a small Node client opens a copy of it and calls downloadToFile (Node's writer opens with "w", no append handle): all 153 files of the channel download fine, sizes match message_attachments.file_size byte for byte. Only the CLI's own writer is affected.
Activity
fix(media): download on Windows without truncating an append handle
ci: windows probe for #233 (throwaway branch)