From 49369873cc5acee0bd2d3cf242a7abf0fda7c3bb Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 6 Jun 2021 22:37:38 +0200 Subject: [PATCH] Update platform.service.ts --- .../src/services/platform.service.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/terminus-electron/src/services/platform.service.ts b/terminus-electron/src/services/platform.service.ts index b44d5de7..bcd315df 100644 --- a/terminus-electron/src/services/platform.service.ts +++ b/terminus-electron/src/services/platform.service.ts @@ -213,3 +213,38 @@ class ElectronFileUpload extends FileUpload { this.file.close() } } + +class ElectronFileDownload extends FileDownload { + private size: number + private file: fs.FileHandle + private buffer: Buffer + + constructor (private filePath: string) { + super() + this.buffer = Buffer.alloc(256 * 1024) + } + + async open (): Promise { + this.size = (await fs.stat(this.filePath)).size + this.file = await fs.open(this.filePath, 'r') + } + + getName (): string { + return path.basename(this.filePath) + } + + getSize (): number { + return this.size + } + + async read (): Promise { + const result = await this.file.read(this.buffer, 0, this.buffer.length, null) + this.increaseProgress(result.bytesRead) + console.log(result) + return this.buffer.slice(0, result.bytesRead) + } + + close (): void { + this.file.close() + } +}