/**
 * ZIP extraction using fflate (global fflate must be loaded).
 * Works in extension popup; use for Google Takeout zip files.
 */
(function (global) {
  'use strict';

  function unzipToFiles(zipArrayBuffer) {
    if (typeof fflate === 'undefined') {
      throw new Error('fflate not loaded. Add lib/fflate.min.js (see README).');
    }
    var entries = fflate.unzipSync(new Uint8Array(zipArrayBuffer));
    var result = {};
    for (var name in entries) {
      if (entries.hasOwnProperty(name) && !name.endsWith('/')) {
        var u = entries[name];
        result[name] = u.buffer.slice(u.byteOffset, u.byteOffset + u.byteLength);
      }
    }
    return result;
  }

  global.GphotoZip = {
    unzipToFiles: unzipToFiles
  };
})(typeof self !== 'undefined' ? self : this);
