tdweb: getFilePart (not tested)

GitOrigin-RevId: 7201a7d4da41bb8f42a934fb149e80e08f9e6309
This commit is contained in:
Arseny Smirnov 2019-02-15 19:19:46 +03:00
parent 75db56dcb3
commit 7a6a506e9e
2 changed files with 28 additions and 2 deletions

View File

@ -19,6 +19,8 @@ const sleep = ms => new Promise(res => setTimeout(res, ms));
* 3. file <..as in td_api..> idb_key:string = File; <br>
* 2. setJsLogVerbosityLevel new_verbosity_level:string = Ok;
* 3. inputFileBlob blob:<javascript blob> = InputFile;<br>
* 4. readFilePart path:string offset:int64 size:int64 = FilePart;<br>
* filePart data:blob = FilePart;<br>
* <br>
*/
class TdClient {

View File

@ -475,6 +475,26 @@ class TdClient {
log.info('ignore on_start');
}
readFilePart(query) {
var res;
try {
//let file_size = this.FS.stat(query.path).size;
var stream = this.FS.open(query.path, 'r');
var buf = new Uint8Array(query.size);
this.FS.read(stream, buf, 0, query.size, query.offset);
this.FS.close(stream);
res = buf
} catch (e) {
this.callback({'@type':'error', '@extra': query['@extra'], code: 400, message: e});
return;
}
this.callback({
'@type': 'FilePart',
'@extra': query['@extra'],
'data': res
}, [res.buffer]);
}
send(query) {
if (this.isClosing) {
return;
@ -498,6 +518,10 @@ class TdClient {
log.setVerbosity(query.new_verbosity_level);
return;
}
if (this.isPending) {
this.pendingQueries.push(query);
return;
}
if (query['@type'] === 'setLogVerbosityLevel' ||
query['@type'] === 'getLogVerbosityLevel' ||
query['@type'] === 'setLogTagVerbosityLevel' ||
@ -506,8 +530,8 @@ class TdClient {
this.execute(query);
return;
}
if (this.isPending) {
this.pendingQueries.push(query);
if (query['@type'] === 'readFilePart') {
this.readFilePart(query);
return;
}
query = this.prepareQuery(query);