From 7a6a506e9e824e45318677258a1987df898929f4 Mon Sep 17 00:00:00 2001 From: Arseny Smirnov Date: Fri, 15 Feb 2019 19:19:46 +0300 Subject: [PATCH] tdweb: getFilePart (not tested) GitOrigin-RevId: 7201a7d4da41bb8f42a934fb149e80e08f9e6309 --- example/web/tdweb/src/index.js | 2 ++ example/web/tdweb/src/worker.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/example/web/tdweb/src/index.js b/example/web/tdweb/src/index.js index 67dfd2cfe..87eab7666 100644 --- a/example/web/tdweb/src/index.js +++ b/example/web/tdweb/src/index.js @@ -19,6 +19,8 @@ const sleep = ms => new Promise(res => setTimeout(res, ms)); * 3. file <..as in td_api..> idb_key:string = File;
* 2. setJsLogVerbosityLevel new_verbosity_level:string = Ok; * 3. inputFileBlob blob: = InputFile;
+ * 4. readFilePart path:string offset:int64 size:int64 = FilePart;
+ * filePart data:blob = FilePart;
*
*/ class TdClient { diff --git a/example/web/tdweb/src/worker.js b/example/web/tdweb/src/worker.js index b5cedff53..2231498dc 100644 --- a/example/web/tdweb/src/worker.js +++ b/example/web/tdweb/src/worker.js @@ -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);