index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. var base64 = require('./base64');
  3. /**
  4. Usage:
  5. zip = new JSZip();
  6. zip.file("hello.txt", "Hello, World!").file("tempfile", "nothing");
  7. zip.folder("images").file("smile.gif", base64Data, {base64: true});
  8. zip.file("Xmas.txt", "Ho ho ho !", {date : new Date("December 25, 2007 00:00:01")});
  9. zip.remove("tempfile");
  10. base64zip = zip.generate();
  11. **/
  12. /**
  13. * Representation a of zip file in js
  14. * @constructor
  15. * @param {String=|ArrayBuffer=|Uint8Array=} data the data to load, if any (optional).
  16. * @param {Object=} options the options for creating this objects (optional).
  17. */
  18. function JSZip(data, options) {
  19. // if this constructor is used without `new`, it adds `new` before itself:
  20. if(!(this instanceof JSZip)) return new JSZip(data, options);
  21. // object containing the files :
  22. // {
  23. // "folder/" : {...},
  24. // "folder/data.txt" : {...}
  25. // }
  26. this.files = {};
  27. this.comment = null;
  28. // Where we are in the hierarchy
  29. this.root = "";
  30. if (data) {
  31. this.load(data, options);
  32. }
  33. this.clone = function() {
  34. var newObj = new JSZip();
  35. for (var i in this) {
  36. if (typeof this[i] !== "function") {
  37. newObj[i] = this[i];
  38. }
  39. }
  40. return newObj;
  41. };
  42. }
  43. JSZip.prototype = require('./object');
  44. JSZip.prototype.load = require('./load');
  45. JSZip.support = require('./support');
  46. JSZip.defaults = require('./defaults');
  47. /**
  48. * @deprecated
  49. * This namespace will be removed in a future version without replacement.
  50. */
  51. JSZip.utils = require('./deprecatedPublicUtils');
  52. JSZip.base64 = {
  53. /**
  54. * @deprecated
  55. * This method will be removed in a future version without replacement.
  56. */
  57. encode : function(input) {
  58. return base64.encode(input);
  59. },
  60. /**
  61. * @deprecated
  62. * This method will be removed in a future version without replacement.
  63. */
  64. decode : function(input) {
  65. return base64.decode(input);
  66. }
  67. };
  68. JSZip.compressions = require('./compressions');
  69. module.exports = JSZip;