2014-04-07 122 views
3

我想在使用AngularJS下載文件時解壓縮壓縮文件。如何使用AngularJs解壓縮壓縮文件?

我用下面的代碼嘗試,

對於如:

<a download="My_File.PNG" target="_self" ng-href="Path of the zip file/My_File.PNG.zip">My_File.PNG</a> 

我如何可以從My_File.PNG.zip實際文件My_File.PNG在瀏覽器?

回答

2

不能從角做直接,但你可以叫使用JSUnzip庫,你可以從你的角度控制器調用https://github.com/augustl/js-unzip

 var myZip = ... // Get it with an XHR request, HTML5 files, etc. 
    var unzipper = new JSUnzip(myZip); 
    unzipper.isZipFile();  // true or false 

    unzipper.readEntries(); // Creates "entries" 
    unzipper.entries;   // Array of JSUnzip.ZipEntry objects. 
+0

沒有工作,沒有大的問題,而試圖打開該文件 錯誤通常是說'this.stream.charCodeAt不是一個函數 JSUnzip.BigEndianBinaryStream.prototype.getByteAt @ ../JS/JS-unzip.js:102' JS-unzip.js線102 'getByteAt:函數(指數){ 返回this.stream.charCodeAt(索引); // \t return this.stream.charCodeAt(index)& 0xff; // patch i found off the net,that also also helpful but }'。 –

0

這是一個有點晚了,但問題是在角度要求。您必須傳遞一個特殊參數,如
$ http.get('...',{responseType:「arraybuffer」})。success(successfunc);
然後繼續解壓縮。搜索此...