Initial commit
This commit is contained in:
16
src/infrastructure/SaveFileDialog.ts
Normal file
16
src/infrastructure/SaveFileDialog.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import fileSaver from 'file-saver';
|
||||
|
||||
export class SaveFileDialog {
|
||||
public static saveText(text: string, fileName: string): void {
|
||||
this.saveBlob(text, 'text/plain;charset=utf-8', fileName);
|
||||
}
|
||||
|
||||
private static saveBlob(file: BlobPart, fileType: string, fileName: string): void {
|
||||
try {
|
||||
const blob = new Blob([file], { type: fileType });
|
||||
fileSaver.saveAs(blob, fileName);
|
||||
} catch (e) {
|
||||
window.open('data:' + fileType + ',' + encodeURIComponent(file.toString()), '_blank', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user