Stuk / jszip

Create, read and edit .zip files with Javascript
https://stuk.github.io/jszip/
Other
9.83k stars 1.3k forks source link

Problem adding files of any extension to zip #430

Open hasher-hasher opened 7 years ago

hasher-hasher commented 7 years ago

I tryied to add .mp4 and .srt files to zip, but i got the message "The data of 'Sintel.mp4' is in an unsupported format"

that is my code

torrent.on('done', function () {
  document.getElementById("downloadProgress").innerHTML = "Download Complete!"
  if(torrent.files.length > 1){
    alert("Is a directory")
    torrent.files.forEach(function (file) {
      if(file.name.split('.').pop() == "mp4"){
        alert(file.name + " added to zip source")
        zip.file(file.name, file, {binary: true})
      }
    })
    zip.generateAsync({type:"blob"})
    .then(function (content) {
      // see FileSaver.js
      saveAs(content, "movie.zip");
    });
  } else {
    alert("Just one file")
  }
})

how can i zip any type of file?

dumblob commented 7 years ago

I'm also interested in this issue as we're using different files and want to guarantee, that all of them will be added without any issues.

dduponchel commented 7 years ago

The message is misleading here: the "format" isn't about the file, it's about how you give the content to JSZip. What's inside torrent.files ? If a file is an object, JSZip won't know how to include it. You need to give a blob, a uint8array, etc