Answered Compress Folder/Files (.zip)

  • 2012년 5월 14일 월요일 오후 11:12
     
     

    Is there anyway we can compress and decompress a folder, and the files inside, and save it as .zip only using htm5/Javascript code?

    I want something like this: function createzip(FolderToBeCompressed, DestinePath) 

    anyone?

모든 응답

  • 2012년 5월 15일 화요일 오후 12:39
    중재자
     
     답변됨

    Hi Alan,

    You can use the Windows.Storage.Compression library to build this archive.  You would need to add each file in the folder however as there is no interface to do an entire folder.

    -Jeff


    Jeff Sanders (MSFT)

  • 2012년 5월 15일 화요일 오후 3:29
     
     

    Hi jpsanders,

    i already checked this library.. there's no sample code or anything that can help. Do you have any sample code?

  • 2012년 5월 16일 수요일 오전 2:01
     
     답변됨

    I had to do the same thing and ended up using a JS zip library instead:

    https://github.com/gildas-lormeau/zip.js

    Even then you need to have quite a large amount of code to read/write files. Since all IO methods in WinJS are asynchronous and you have no way of reading entire folders you have to read/write all files one by one, *all* asynchronously. Unfortunately I can't share my code.

    It is definitely possible but very tedious. I probably wrote 200 lines of code just to compress/extract a zip file to/from a folder.

  • 2012년 5월 16일 수요일 오전 3:35
     
     

    anyone with a code using Windows.Storage.Compression in JAVASCRIPT?

    This site doesn't have any tutorial or sample or even reference to use this thing. 

  • 2012년 5월 16일 수요일 오전 7:25
    중재자
     
     

    Did you look at the Compression sample?

    --Rob

  • 2012년 5월 16일 수요일 오후 3:22
     
     

    yes and it's compressing a single file and decompressing as a single file. There's no clue in that code showing a way to make that to compress multiple files into a SINGLE file (like a zip) AND more important, decompressing the single file extracting multiple files from it.

  • 2012년 5월 16일 수요일 오후 3:40
    중재자
     
     답변됨

    As Jeff said, there is no interface for a folder so you would need to do each file separately. There is a higher level ZipArchive class in .Net's System.IO.Compression namespace which you could expose as Windows Runtime component (note that the documentation is for the desktop .Net configuration and not all methods listed there are available to Metro style apps).

    If you want something beyond what is provided by the system you would need to use a 3rd party compression library like Patrick suggested.

    --Rob

  • 2012년 5월 17일 목요일 오후 8:35
     
     
    nevermind.. already did that
  • 2012년 5월 18일 금요일 오전 9:09
     
     
    Why not publish your code? Would make a nice WinRT extension library
  • 2012년 5월 18일 금요일 오후 3:15
     
     
    i'll do that, but first i have to finish it and do more tests to make sure it's working fine
  • 2012년 10월 21일 일요일 오후 3:55
     
     
    Darn, too bad there's no way to do a whole folder natively in Javascript!  That would have been really helpful.  As an example, I'm trying to add a button for a user to gather logs and it would be nice to have them end up with a zip file.  Instead I will just create a folder.
  • 2012년 10월 21일 일요일 오후 6:53
     
     
    we have a working unzip component and will release it soon on github. Might implement zipping first though.