我正在使用HTML/JS在Windows 8上工作。我试图提取一个使用FilePicker选择的Zip文件。
为了提取Zip文件,我正在使用这个页面中的函数:http://blog.appliedis.com/2013/09/18/zipping-and-unzipping-files-in-a-winjs-application/
在此链接中有一个用于提取Zip文件的函数
在此之前,我将
请帮忙,我该如何将该库集成到我的项目中。这是我的项目链接。
编辑:
为了提取Zip文件,我正在使用这个页面中的函数:http://blog.appliedis.com/2013/09/18/zipping-and-unzipping-files-in-a-winjs-application/
在此链接中有一个用于提取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
库添加到项目文件夹中。请帮忙,我该如何将该库集成到我的项目中。这是我的项目链接。
编辑:
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文件的其他库,请建议我。