最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add files to an existing zip archive via JSZip - Stack Overflow

programmeradmin1浏览0评论

I have a zip file which is a Visual Basic project. What I'm trying to see is if I can add my web app as a directory inside this zip archive so I can easily export my web apps as native windows apps

I tried the Ajax method from the documentation and it worked fine on my hard drive when loaded in Firefox, but it's not calling when from my website!

$(document).ready(function() {
  $(".download").on("click", function() {
    JSZipUtils.getBinaryContent('YourWinApp.zip', function(err, data) {
      if(err) {
        throw err; // or handle err
      }

      var zip = new JSZip(data);
      zip.file("Hello.txt", "Hello World\n");
      var folder = zip.folder("images");
      folder.file("folder.txt", "I'm a file in a new folder");
      var content = zip.generate({type:"blob"});
      // see FileSaver.js
      saveAs(content, "example.zip");
    });

  });
});

I have a zip file which is a Visual Basic project. What I'm trying to see is if I can add my web app as a directory inside this zip archive so I can easily export my web apps as native windows apps

I tried the Ajax method from the documentation and it worked fine on my hard drive when loaded in Firefox, but it's not calling when from my website!

$(document).ready(function() {
  $(".download").on("click", function() {
    JSZipUtils.getBinaryContent('YourWinApp.zip', function(err, data) {
      if(err) {
        throw err; // or handle err
      }

      var zip = new JSZip(data);
      zip.file("Hello.txt", "Hello World\n");
      var folder = zip.folder("images");
      folder.file("folder.txt", "I'm a file in a new folder");
      var content = zip.generate({type:"blob"});
      // see FileSaver.js
      saveAs(content, "example.zip");
    });

  });
});
Share Improve this question edited Feb 27, 2015 at 9:18 Michael Schwartz asked Feb 26, 2015 at 8:47 Michael SchwartzMichael Schwartz 8,45514 gold badges90 silver badges153 bronze badges 3
  • How do you include it ? With the file in jszip dist/ folder ? – David Duponchel Commented Feb 26, 2015 at 17:37
  • require is not defined is the error. gee maybe require is not defined in your project? The tutorial probably uses RequireJS – Secret Commented Feb 27, 2015 at 5:07
  • I got it to work on my hard drive locally on my machine, but doesn't call on my website. Can anyone help? – Michael Schwartz Commented Feb 27, 2015 at 9:20
Add a ment  | 

1 Answer 1

Reset to default 5

I tried the Ajax method from the documentation and it worked perfectly! (I didn't link to the right file lol)

$(document).ready(function() {
  $(".download").on("click", function() {
    JSZipUtils.getBinaryContent('YourWindowsApp.zip', function(err, data) {
      if(err) {
        throw err; // or handle err
      }

      var zip = new JSZip(data);
      zip.file("Hello.txt", "Hello World\n");
      var folder = zip.folder("images");
      folder.file("folder.txt", "I'm a file in a new folder");
      var content = zip.generate({type:"blob"});
      // see FileSaver.js
      saveAs(content, "example.zip");
    });

  });
});
发布评论

评论列表(0)

  1. 暂无评论