-
Notifications
You must be signed in to change notification settings - Fork 14
/
ZipFileExporter.js~
72 lines (57 loc) · 1.61 KB
/
ZipFileExporter.js~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* This script requires jszip.js
*
* @author Ikaros Kappler
* @date 2013-09-05
* @version 1.0.0
**/
function exportZipFile( stringData, filename ) {
/*
if( !filename )
filename = "zipData.zip";
if( !mimeType )
mimeType = "application/zip";
var blob = new Blob([stringData], {type: mimeType});
saveAs(blob, filename);
*/
var zip = new JSZip();
//zip.file("Hello.txt", "Comment ...\n" ); // "Hello World\n");
//var img = zip.folder("images");
//img.file("smile.gif", imgData, {base64: true});
// Remember: btoa() converts string data to base64,
// atob() converts base64 data to string.
stringData = "{ test: \"true\" }";
//b64 = btoa( stringData );
//window.alert( "base64=" + b64 );
/*
zip.file( "test.dat",
b64, // new Blob( [ btoa("blubber_bla") ],
//{ type: "text/plain",
// base64: true }
//)
{ //type: "text/plain",
base64: true }
);
*/
zip.file( "test.json",
stringData,
{ base64: false,
binary: false,
type: "application/json"
}
);
// The generate-function returns a base64 string
var zipData = zip.generate( { type: "base64" } );
window.alert( "zipData=" + zipData );
//location.href="data:application/zip;base64,"+content;
//window.alert( content );
var blob = new Blob( [zipData],
{type: "application/zip; base64"}
);
window.saveAs(blob, filename);
/*
var writer = new FileWriter();
writer.write( blob );
*/
//saveTextFile( content, filename, "application/zip" );
}