1+ /**
2+ * @deprecated
3+ */
14export function downloadBlob ( byteData : any , filename = 'file.zip' , type = 'application/octet-stream' ) {
5+ console . warn ( "Caution, deprecated function downloadBlob was called. Use downloadByteData methods instead." ) ;
26 const blob = new Blob ( [ JSON . stringify ( byteData ) ] , {
37 type : type
48 } )
@@ -17,5 +21,38 @@ export function downloadBlob(byteData: any, filename = 'file.zip', type = 'appli
1721 } )
1822 ) ;
1923
24+ document . body . removeChild ( link ) ;
25+ }
26+
27+ export function downloadByteData ( byteData : any , filename = 'file.zip' , type = 'application/octet-stream' ) {
28+ const blob = new Blob ( [ JSON . stringify ( byteData ) ] , {
29+ type : type
30+ } ) ;
31+ download ( blob , filename ) ;
32+ }
33+
34+ export function downloadJsonData ( jsonData : any , filename = 'file.json' , type = 'application/json' ) {
35+ const blob = new Blob ( [ JSON . stringify ( jsonData ) ] , {
36+ type : type
37+ } ) ;
38+ download ( blob , filename ) ;
39+ }
40+
41+ export function download ( blob : Blob , filename = 'file.zip' ) {
42+ const blobUrl = URL . createObjectURL ( blob ) ;
43+
44+ // Create a link element
45+ const link = document . createElement ( "a" ) ;
46+ link . href = blobUrl ;
47+ link . download = filename ;
48+ document . body . appendChild ( link ) ;
49+ link . dispatchEvent (
50+ new MouseEvent ( 'click' , {
51+ bubbles : true ,
52+ cancelable : true ,
53+ view : window
54+ } )
55+ ) ;
56+
2057 document . body . removeChild ( link ) ;
2158}
0 commit comments