locked
Extract ZIp File Using Library JSZip

    Question

  • I am working in windows 8 using HTML/JS. I am trying to Extract a Zip file which is picked file using FilePicker.

    To extract Zip file I am using this forum.

    In this Link there is a function to Extract Zip file 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);
            });
    }

     

    Before this I added JSZIP Library to Project folder. But when run this function I am getting the error.

    Help me, How Can I integrate the Library to my project. Here is my sample Project

    Edit:

    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;
            });
    }

    Now it is working with out error. But it is not doing any thing like extracting my file.

    NOTE:

    - If anyone knows any another way which better than this or other Library which I can use to extract file for WinJS; please suggest me. 


    devendra

    • Edited by GDEVENDRAK Tuesday, December 17, 2013 6:13 AM
    Thursday, December 12, 2013 2:29 PM

Answers

All replies

  • you can try the built in WinJS library, check this

    http://code.msdn.microsoft.com/Decompressing-Sample-54178871

     
    • Proposed as answer by Ahmed-Fouad Friday, December 13, 2013 1:40 AM
    • Marked as answer by GDEVENDRAK Friday, December 20, 2013 1:00 PM
    Friday, December 13, 2013 1:39 AM
  •  @Ahmed-Fouad

     Your Sample is not working properly. I am getting exception after Extraction. 

     MSG1.Text = string.Format("Your File is decompressed at {0}"+folder.Path); 

     Where you are showing result message.

    Here are the ScreenShots.  Here I tried to extract your Sample Zip file & you can see all folder contains in the ZIp file are extracted in main folder means it is not properly extracted.

    Here is the Class1.cs file.
    Now it is working as exact extracted Zip file.


    Please try to change your code in sample if it is worth-full,
    Thank You for great sample.


    devendra




    • Edited by GDEVENDRAK Friday, December 20, 2013 12:59 PM
    Friday, December 13, 2013 5:29 AM