Code Monkey home page Code Monkey logo

meteor-jszip's Introduction

jszip

NO LONGER MAINTAINED

A Zip package for Meteor. Create, read and edit .zip files on server.

This package packs JSZip and adds a saveAs method to the zip instance for convenience.

##Install

meteor add udondan:jszip

##Documnentation

Full documentation of the API at the original package JSZip.

##Usage

var zip = new JSZip();

// Add content to Zip file
zip.file('textfile.txt', 'Hello World');
zip.file('folder/image.jpg', binaryContent);
zip.file('folder/document.pdf', binaryContentBase64Encoded, {base64: true});

// Save to file on server
zip.saveAs("/path/to/filename.zip");

Optionally you can pass a callback function

zip.saveAs("/path/to/filename.zip", function(error, result) {
    // ...
});

If in an unknown environment you want to save to a folder within the meteor structure, e.g. the public folder you can use process.env["PWD"] to get to the absolute path:

var path = process.env["PWD"] + "/public/";
zip.saveAs(path + "filename.zip");

In an older Meteor version (before 0.6.5?) you could get to the public folder via Meteor.chroot.

For creating a zip on the fly, here is an example with an Iron Router route:

Router.map(function() {
  this.route('zip', {
    where: 'server',
    path: 'zip',
    action: function() {
      var self = this;
            
      // Create zip
      var zip = new JSZip();
      
      // Add a file to the zip
      zip.file('textfile.txt', 'Hello World');
      
      // Generate zip stream
      var output = zip.generate({
        type:        "nodebuffer",
        compression: "DEFLATE"
      });
      
      // Set headers
      self.response.setHeader("Content-Type", "application/octet-stream");
      self.response.setHeader("Content-disposition", "attachment; filename=filename.zip");
      self.response.writeHead(200);
      
      // Send content
      self.response.end(output);
    }
  });
});

meteor-jszip's People

Contributors

udondan avatar

Stargazers

 avatar Fabio Dias Rollo avatar oreeng42 avatar Yaşar İÇLİ avatar Bogdan Mustata avatar David Bismut avatar Katja Lutz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.