This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separates all node.js code and makes backup manager browser fri…
…endly
- Loading branch information
Showing
10 changed files
with
123 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IFileServiceConfig { | ||
enableLog: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as fs from 'fs'; | ||
import { IFileServiceConfig } from './file.models'; | ||
|
||
export class FileService { | ||
|
||
constructor(private config: IFileServiceConfig) { | ||
} | ||
|
||
private readonly zipExtension: string = '.zip'; | ||
|
||
|
||
async loadFileAsync(fileNameWithoutExtension: string): Promise<Buffer> { | ||
const filePath = this.getFilePath(fileNameWithoutExtension); | ||
|
||
if (this.config.enableLog) { | ||
console.log(`Reading file '${filePath}'`); | ||
} | ||
const file = await fs.promises.readFile(filePath); | ||
if (this.config.enableLog) { | ||
console.log(`Reading file completed`); | ||
} | ||
|
||
return file; | ||
} | ||
|
||
async writeFileAsync(fileNameWithoutExtension: string, content: any): Promise<void> { | ||
const filePath = this.getFilePath(fileNameWithoutExtension); | ||
|
||
console.log(`Writing file '${filePath}'`); | ||
await fs.promises.writeFile(filePath, content); | ||
console.log(`File saved`); | ||
} | ||
|
||
private getFilePath(fileNameWithoutExtension: string) { | ||
const filenameWithExtension = fileNameWithoutExtension + this.zipExtension; | ||
return`./${filenameWithExtension}`; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './file/file.service'; | ||
export * from './file/file.models'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export type ZipContext = 'node.js' | 'browser'; | ||
|
||
export interface IZipServiceConfig { | ||
filename: string; | ||
enableLog: boolean; | ||
context: ZipContext | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters