index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /**
  3. * Representation a of zip file in js
  4. * @constructor
  5. */
  6. function JSZip() {
  7. // if this constructor is used without `new`, it adds `new` before itself:
  8. if(!(this instanceof JSZip)) {
  9. return new JSZip();
  10. }
  11. if(arguments.length) {
  12. throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");
  13. }
  14. // object containing the files :
  15. // {
  16. // "folder/" : {...},
  17. // "folder/data.txt" : {...}
  18. // }
  19. // NOTE: we use a null prototype because we do not
  20. // want filenames like "toString" coming from a zip file
  21. // to overwrite methods and attributes in a normal Object.
  22. this.files = Object.create(null);
  23. this.comment = null;
  24. // Where we are in the hierarchy
  25. this.root = "";
  26. this.clone = function() {
  27. var newObj = new JSZip();
  28. for (var i in this) {
  29. if (typeof this[i] !== "function") {
  30. newObj[i] = this[i];
  31. }
  32. }
  33. return newObj;
  34. };
  35. }
  36. JSZip.prototype = require('./object');
  37. JSZip.prototype.loadAsync = require('./load');
  38. JSZip.support = require('./support');
  39. JSZip.defaults = require('./defaults');
  40. // TODO find a better way to handle this version,
  41. // a require('package.json').version doesn't work with webpack, see #327
  42. JSZip.version = "3.7.1";
  43. JSZip.loadAsync = function (content, options) {
  44. return new JSZip().loadAsync(content, options);
  45. };
  46. JSZip.external = require("./external");
  47. module.exports = JSZip;