Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何使用JavaScript压缩解压zip包 #37

Open
gnipbao opened this issue Dec 5, 2019 · 0 comments
Open

如何使用JavaScript压缩解压zip包 #37

gnipbao opened this issue Dec 5, 2019 · 0 comments

Comments

@gnipbao
Copy link
Owner

gnipbao commented Dec 5, 2019

JSZip是一个JavaScript库 可以很方便的用来读写.zip文件同时可以用在服务器端

压缩文件

  let zip = new JSZip();
  zip.file("Hello.txt", "Hello World\n");
  let img = zip.folder("images");
  img.file("smile.gif", imgData, { base64: true });
  zip.generateAsync({ type: "blob" }).then(function(content) {
    // see FileSaver.js
    saveAs(content, "example.zip");
  });

解压文件

 fetch("test.zip")
    .then(response => response.arrayBuffer())
    .then(JSZip.loadAsync)
    .then(zip => {
    // use file index for file
      zip
        .file("test.json")
        .async("uint8array")
        .then(u => console.log(u));
    });

相关开源库

JSZip
FileSaver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant