Make Python-client downloads transactional and verify them against the file metadata Girder already returns. Today GirderClient.downloadFile opens the destination before it knows whether the HTTP request or streamed body will succeed, so an error response, interrupted connection, or corrupt body can destroy a good local file.
Extend the public method to downloadFile(fileId, path, size=None, sha512=None, progressCallback=None). The existing two-argument call must remain valid. A successful HTTP 200 download must produce exactly the response bytes at path, but the destination must not change while bytes are arriving: replace it only after the complete body has passed all requested checks and callbacks. If the destination did not exist, a failed operation must not create it. No staging artifacts may remain after success or failure, and empty chunks yielded by the HTTP library are keep-alives rather than end-of-file or progress events.
Reject every non-200 response before consuming its body by raising the existing HttpError, populated with the response status, text and URL and method GET. Streaming exceptions must propagate. In either case, preserve an existing destination.
When size is not None, require the final byte count to equal it, including the explicit value zero. A short or long body raises the new public IncorrectDownloadLengthError, whose expected and actual attributes contain the requested and observed byte counts. When sha512 is not None, compare it case-insensitively with the SHA-512 hex digest of the received bytes. A mismatch raises the new public IncorrectDownloadChecksumError; its expected attribute preserves the caller-supplied digest and its actual attribute is the computed lowercase hex digest. Validation failures are transactional too.
When progressCallback is callable, invoke it after each non-empty response chunk with {'current': bytes_received, 'total': size}. Thus total is None when no expected size was supplied. Callback exceptions propagate and abort the commit just like transfer or validation failures.
Finally, make downloadItem apply these guarantees to every file it downloads, in both its single-file and directory layouts: use each file document's size as the expected length and its sha512 as the expected digest when that field exists. File documents from assetstores that omit sha512 must continue to download successfully using length validation alone.