windows 8 - How can I save a zip file to local storage in a win8 app using JSZip? -


i'm able create jszip object in code, i'm having trouble saving local storage in windows 8 app. examples i'm able find set browser's location.href trigger download, isn't option me.

i've included code below. zip file end invalid , can't opened. appreciated.

for reference: jszip

        function _ziptest() {         var dbfile = null;         var zipdata = null;         windows.storage.storagefile.getfilefrompathasync(config.db.path)             .then(function (file) {                 dbfile = file;                 return windows.storage.fileio.readbufferasync(file);             })             .then(function (buffer) {                 //read database file byte array , create new zip file                 zipdata = new uint8array(buffer.length);                 var datareader = windows.storage.streams.datareader.frombuffer(buffer);                 datareader.readbytes(zipdata);                 datareader.close();                  var localfolder = windows.storage.applicationdata.current.localfolder;                 return localfolder.createfileasync(dbfile.displayname.concat('.zip'), windows.storage.creationcollisionoption.replaceexisting)             })             .then(function (file) {                 //write zip data new zip file                 var zip = new jszip();                 zip.file(dbfile.displayname, zipdata);                 var content = zip.generate();                  return windows.storage.fileio.writetextasync(file, content);             });     } 

you can on these lines. code seem generate valid .zip file in temp folder.

    var zip = new jszip();     var storage = windows.storage;     storage.storagefile.getfilefromapplicationuriasync(new windows.foundation.uri('ms-appx:///images/logo.png')).then(function ongetfile(file)     {         var blob = msapp.createfilefromstoragefile(file);         var url = url.createobjecturl(blob, { onetimeonly: true });         return winjs.xhr({ url: url, responsetype: 'arraybuffer' });     }).then(function onreadbuffer(req)     {         var b = req.response;         zip.file('logo.png', b);         return storage.applicationdata.current.temporaryfolder.createfileasync('a.zip', storage.creationcollisionoption.replaceexisting);     }).then(function onnewfile(out)     {         var content = zip.generate({ type: 'uint8array' });         return storage.fileio.writebytesasync(out, content);     }).then(null, function onerror(error)     {         // todo: error handling     }); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -