Allow zero count in readFilePart.
GitOrigin-RevId: 97e6f7defe69d1993542c356798961333b061e39
This commit is contained in:
parent
be685c7a6d
commit
4d0fed097a
@ -3261,7 +3261,9 @@ setFileGenerationProgress generation_id:int64 expected_size:int32 local_prefix_s
|
||||
finishFileGeneration generation_id:int64 error:error = Ok;
|
||||
|
||||
//@description Reads a part of a file from the TDLib file cache and returns read bytes. This method is intended to be used only if the client has no direct access to TDLib's file system, because it is usually slower than a direct read from the file
|
||||
//@file_id Identifier of the file. The file must be located in the TDLib file cache @offset The offset from which to read the file @count Number of bytes to read. An error will be returned if there are not enough bytes available in the file from the specified position
|
||||
//@file_id Identifier of the file. The file must be located in the TDLib file cache
|
||||
//@offset The offset from which to read the file
|
||||
//@count Number of bytes to read. An error will be returned if there are not enough bytes available in the file from the specified position. Pass 0 to read all available data from the specified position
|
||||
readFilePart file_id:int32 offset:int32 count:int32 = FilePart;
|
||||
|
||||
//@description Deletes a file from the TDLib file cache @file_id Identifier of the file to delete
|
||||
|
@ -1831,14 +1831,19 @@ void FileManager::read_file_part(FileId file_id, int32 offset, int32 count, int
|
||||
if (offset < 0) {
|
||||
return promise.set_error(Status::Error(400, "Parameter offset must be non-negative"));
|
||||
}
|
||||
if (count <= 0) {
|
||||
return promise.set_error(Status::Error(400, "Parameter count must be positive"));
|
||||
if (count < 0) {
|
||||
return promise.set_error(Status::Error(400, "Parameter count must be non-negative"));
|
||||
}
|
||||
|
||||
auto file_view = FileView(node);
|
||||
|
||||
if (count == 0) {
|
||||
count = narrow_cast<int32>(file_view.downloaded_prefix(offset));
|
||||
if (count == 0) {
|
||||
return promise.set_value(td_api::make_object<td_api::filePart>());
|
||||
}
|
||||
} else if (file_view.downloaded_prefix(offset) < static_cast<int64>(count)) {
|
||||
// TODO this check is safer to do in another thread
|
||||
if (file_view.downloaded_prefix(offset) < static_cast<int64>(count)) {
|
||||
return promise.set_error(Status::Error(400, "There is not enough downloaded bytes in the file to read"));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user