load.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. var base64 = require('./base64');
  3. var utf8 = require('./utf8');
  4. var utils = require('./utils');
  5. var ZipEntries = require('./zipEntries');
  6. module.exports = function(data, options) {
  7. var files, zipEntries, i, input;
  8. options = utils.extend(options || {}, {
  9. base64: false,
  10. checkCRC32: false,
  11. optimizedBinaryString : false,
  12. createFolders: false,
  13. decodeFileName: utf8.utf8decode
  14. });
  15. if (options.base64) {
  16. data = base64.decode(data);
  17. }
  18. zipEntries = new ZipEntries(data, options);
  19. files = zipEntries.files;
  20. for (i = 0; i < files.length; i++) {
  21. input = files[i];
  22. this.file(input.fileNameStr, input.decompressed, {
  23. binary: true,
  24. optimizedBinaryString: true,
  25. date: input.date,
  26. dir: input.dir,
  27. comment : input.fileCommentStr.length ? input.fileCommentStr : null,
  28. unixPermissions : input.unixPermissions,
  29. dosPermissions : input.dosPermissions,
  30. createFolders: options.createFolders
  31. });
  32. }
  33. if (zipEntries.zipComment.length) {
  34. this.comment = zipEntries.zipComment;
  35. }
  36. return this;
  37. };