我正在使用HTML/JS的Windows 8中工作。我正在嘗試使用FilePicker提取一個Zip文件。使用庫提取ZIp文件JSZip
提取Zip文件我使用這個page。
在這個環節上存在提取Zip文件unzipAsync
function unzipAsync(filePath, replaceIfExists) {
var fileCollisionOption = replaceIfExists ?
storage.CreationCollisionOption.replaceExisting :
storage.CreationCollisionOption.failIfExists;
return storage.StorageFile
.getFileFromPathAsync(filePath)
.then(getFileAsUint8Array)
.then(function (zipFileContents) {
//Create the zip data in memory
var zip = new JSZip(zipFileContents);
//Extract files
var promises = [];
var lf = storage.ApplicationData.current.localFolder;
_.each(zip.files, function (zippedFile) {
//Create new file
promises.push(lf
.createFileAsync(zippedFile.name, fileCollisionOption)
.then(function (localStorageFile) {
//Copy the zipped file's contents into the local storage file
var fileContents = zip.file(zippedFile.name).asUint8Array();
return storage.FileIO
.writeBytesAsync(localStorageFile, fileContents);
})
);
});
return WinJS.Promise.join(promises);
});
}
函數這個我添加JSZIP
圖書館項目文件夾之前。
幫助我,我如何將圖書館整合到我的項目中。這裏是我的項目Link
編輯:
function getFileAsUint8Array(file) {
return storage.FileIO.readBufferAsync(file)
.then(function (buffer) {
//Read the file into a byte array
var fileContents = new Uint8Array(buffer.length);
var dataReader = storage.Streams.DataReader.fromBuffer(buffer);
dataReader.readBytes(fileContents);
dataReader.close();
return fileContents;
});
}
現在,它正在與出錯誤。但它並沒有像提取我的文件那樣做任何事情。
注:
- 如果有人知道任何一種方式,其比這或我可以用它來提取WinJS文件的其他圖書館更好;請給我建議。
不幸的是,我不明白你的代碼。你可以添加更多的描述性或任何來源鏈接將是有益的。 是的,我正在miising'getFileAsUint8Array'函數。添加功能後,我沒有得出結論。 謝謝 – Kumar
沒有源代碼鏈接...這是代碼。至於'getFileAsUnit8Array'函數...你會得到一個不同的錯誤?你的問題仍然說你得到了'未定義'的錯誤......你呢?還是你看到別的東西? – jakerella
嗨,我編輯我的問題,我忘了更改我的帖子中的描述。 &我只是休耕這個鏈接[http://blog.appliedis.com/2013/09/18/zipping-and-unzipping-files-in-a-winjs-application/] 你可以嘗試我的樣本項目我加了。我無法更改我的項目中的編輯。現在我失業了。謝謝 – Kumar