Generate a JSZip.CompressedObject for a given zipOject.
@param {ZipObject} file the object to read.
@param {JSZip.compression} compression the compression to use.
@return {JSZip.CompressedObject} the compressed result.
329534
function (file, compression) {
      var result = new JSZip.CompressedObject(), content;

      // the data has not been decompressed, we might reuse things !
      if (file._data instanceof JSZip.CompressedObject) {
         result.uncompressedSize = file._data.uncompressedSize;
         result.crc32 = file._data.crc32;

         if (result.uncompressedSize === 0 || file.options.dir) {
            compression = JSZip.compressions['STORE'];
            result.compressedContent = "";
            result.crc32 = 0;
         } else if (file._data.compressionMethod === compression.magic) {
            result.compressedContent = file._data.getCompressedContent();
         } else {
            content = file._data.getContent()
            // need to decompress / recompress
            result.compressedContent = compression.compress(JSZip.utils.transformTo(compression.compressInputType, content));
         }
      } else {
         // have uncompressed data
         content = getBinaryData(file);
         if (!content || content.length === 0 || file.options.dir) {
            compression = JSZip.compressions['STORE'];
            content = "";
         }
         result.uncompressedSize = content.length;
         result.crc32 = this.crc32(content);
         result.compressedContent = compression.compress(JSZip.utils.transformTo(compression.compressInputType, content));
      }

      result.compressedSize = result.compressedContent.length;
      result.compressionMethod = compression.magic;

      return result;
   }
564063
function unzip(file, callback) {
    var metafile = metapath(file);
    // return cached result of unzipped file
    // intentionally sync here to avoid race condition unzipping
    // same file for multiple layers
    try {
        var meta_data = fs.readFileSync(metafile);
        if (meta_data) {
            var meta = JSON.parse(meta_data);
            var dest_file = meta['unzipped_file'];
            if (dest_file && existsSync(dest_file)) {
                if (env == 'development') console.error('[millstone] found previously unzipped file: ' + dest_file);
                return callback(null,dest_file);
            }
        } else {
            if (env == 'development') console.error('[millstone] empty meta file for zipfile: ' + metafile);
        }
    }
    catch (err) {
        if (env == 'development') console.error('[millstone] error opening meta file for zipfile: ' + err.message);
    }
    var zf;
    try {
        zf = new zipfile.ZipFile(file);
    } catch (err) {
        return callback(err);
    }

    if (zf.names.length < 1) {
        return callback(new Error("could not find any valid data in zip archive: '" + file + "'"));
    }

    var remain = zf.names.length;
    var ds_files = _(zf.names).chain()
        .reject(function(name) {
            return (name && (name[0] === '.' || path.basename(name)[0] === '.'));
        })
        .map(function(name) {
            if (!valid_ds_extensions[path.extname(name).toLowerCase()]) return;
            var new_name = path.join(
                path.dirname(file),
                path.basename(file, path.extname(file)) +
                path.extname(name).toLowerCase());
            return {new_name:new_name,original_name:name};
        })
        .uniq()
        .compact()
        .value();

    if (!ds_files || ds_files.length < 1) return callback(new Error("Valid datasource not detected (by extension) in zip: '" + file + "'"));

    var original_name = ds_files[0].original_name;
    var new_name = ds_files[0].new_name;

    var len = Object.keys(ds_files).length;
    if (len > 1) {
        // prefer first .shp
        for (var i=0;i<len;++i) {
            var fname = ds_files[i].original_name;
            if (path.extname(fname) == '.shp') {
                original_name = fname;
                new_name = ds_files[i].new_name;
                break;
            }
        }
        if (env == 'development') {
            console.warn('[millstone] warning: detected more than one file in zip (by ext) that may be valid: ');
            for (var i=0;i<len;++i) {
                console.warn('[millstone]   ' + ds_files[i].original_name);
            }
            console.warn('[millstone] picked: ' + original_name);
        }
    }

    if (!new_name) return callback(new Error("Valid datasource not detected (by extension) in zip: '" + file + "'"));

    if (env == 'development') {
        console.warn('[millstone] renaming ' + original_name + ' to ' + new_name);
    }

    // only unzip files that match our target name
    // naive '(name.indexOf(search_basename) < 0)' does the trick
    // yes this is simplistic, but its better than corrupt data: https://github.com/mapbox/millstone/issues/99
    var search_basename = path.basename(original_name,path.extname(original_name));
    zf.names.forEach(function(name) {
        // Skip directories, hiddens.
        var basename = path.basename(name);
        if (!path.extname(name) || (name.indexOf(search_basename) < 0) || name[0] === '.' || basename[0] === '.') {
            remain--;
            if (!remain) callback(null, new_name);
        } else {
            // We're brutal in our expectations -- don't support nested
            // directories, and rename any file from `arbitraryName.SHP`
            // to `[hash].shp`.
            var dest = path.join(
                path.dirname(file),
                path.basename(file, path.extname(file)) +
                path.extname(name).toLowerCase()
            );
            zf.copyFile(name, dest, function(err) {
                if (err) return callback(err);
                remain--;
                if (!remain) {
                    add_item_to_metafile(metafile,'unzipped_file',new_name,function(err) {
                        // ignore error from add_item_to_metafile
                        //if (err && env == 'development') console.error('[millstone] ' + err.message);
                        if (err) throw err;
                        callback(null, new_name);
                    });
                }
            });
        }
    });
}
440870
public static ZipFile createZipFile(final File f) throws ZipException, IOException {
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<ZipFile>() {
                @Override
                public ZipFile run() throws IOException {
                    return new ZipFile(f);
                }
            });
        } catch (PrivilegedActionException e) {
            if (e.getCause() instanceof ZipException)
                throw (ZipException) e.getCause();
            throw (IOException) e.getCause();
        }
    }
499350
private static ZipOutputStream getZipOutputStream(File zipFile, Charset charset) {
		return getZipOutputStream(FileUtil.getOutputStream(zipFile), charset);
	}
409030
public static ISObject zip(ISObject... objects) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ZipOutputStream zos = new ZipOutputStream(baos);
        try {
            for (ISObject obj : objects) {
                ZipEntry entry = new ZipEntry(obj.getAttribute(SObject.ATTR_FILE_NAME));
                InputStream is = obj.asInputStream();
                zos.putNextEntry(entry);
                copy(is, zos, false);
                zos.closeEntry();
            }
        } catch (IOException e) {
            throw E.ioException(e);
        } finally {
            close(zos);
        }
        return SObject.of(Codec.encodeUrl(S.random()), baos.toByteArray());
    }
660376
public static ByteSource asCompressedByteSource(File f) throws IOException {
    return GZIPByteSource.fromCompressed(Files.asByteSource(f));
  }
226119
function File (schema) {
  /**
   * The {@link Schema} that this file belongs to.
   *
   * @type {Schema}
   */
  this.schema = schema;

  /**
   * The file's full (absolute) URL, without any hash
   *
   * @type {string}
   */
  this.url = '';

  /**
   * The file's data. This can be any data type, including a string, object, array, binary, etc.
   *
   * @type {*}
   */
  this.data = undefined;

  /**
   * The file's MIME type (e.g. "application/json", "text/html", etc.), if known.
   *
   * @type {?string}
   */
  this.mimeType = undefined;

  /**
   * The file's encoding (e.g. "utf-8", "iso-8859-2", "windows-1251", etc.), if known
   *
   * @type {?string}
   */
  this.encoding = undefined;

  /**
   * Internal stuff. Use at your own risk!
   *
   * @private
   */
  this[__internal] = {
    /**
     * Keeps track of the state of each file as the schema is being read.
     *
     * @type {number}
     */
    state: 0,
  };
}
283634
function (file) {
      var result = getRawData(file), type = JSZip.utils.getTypeOf(result);
      if (type === "string") {
         if (!file.options.binary) {
            // unicode text !
            // unicode string => binary string is a painful process, check if we can avoid it.
            if (JSZip.support.uint8array && typeof TextEncoder === "function") {
               return TextEncoder("utf-8").encode(result);
            }
            if (JSZip.support.nodebuffer) {
               return new Buffer(result, "utf-8");
            }
         }
         return file.asBinary();
      }
      return result;
   }
530467
function(file) {
    var result = getRawData(file),
        type = utils.getTypeOf(result);
    if (type === "string") {
        if (!file.options.binary) {
            // unicode text !
            // unicode string => binary string is a painful process, check if we can avoid it.
            if (textEncoder) {
                return textEncoder.encode(result);
            }
            if (support.nodebuffer) {
                return nodeBuffer(result, "utf-8");
            }
        }
        return file.asBinary();
    }
    return result;
}
687772
private void writeCompressedText(File file, byte[] compressedContent) throws IOException
    {
        ByteArrayInputStream bais   = new ByteArrayInputStream(compressedContent);
        GZIPInputStream      gis    = new GZIPInputStream(bais);
        BufferedReader       input  = new BufferedReader(new InputStreamReader(gis));
        BufferedWriter       output = new BufferedWriter(new FileWriter(file));
        String               line;

        while ((line = input.readLine()) != null)
        {
            output.write(line);
            output.write('\n');
        }
        input.close();
        gis.close();
        bais.close();
        output.close();
    }
892930
function _minFile(rawFile, compressedFile) {
    if (compressedFile.size < rawFile.size) {
        return qfs.move(compressedFile.name, rawFile.name)
            .then(function () {
                return new File(rawFile.name, compressedFile.size);
            });
    }

    return compressedFile.remove()
        .then(function () {
            return rawFile;
        });
}
1169198
public File getMinifiedFile(File file) {
        File output = getOutputFile(file);
        return new File(output.getParentFile().getAbsoluteFile(),
                output.getName().replace(".js", googleClosureMinifierSuffix + ".js"));
    }
925558
public static void zip(File source, File target, String compressFileName) throws IOException {
		$.notNull(source);
		zip(new File[] { source }, target, compressFileName);
	}
193159
function Request__compress(response) {
        var accept = this.getRequestHeader('Accept-Encoding'),
            isForCompress = (Type.isString(response) || response instanceof Buffer) && !this.isCompressed,
            that = this;

        if (this.isRendered) {
            // we have multiple recursion in parse for catching
            return false;
        }


        if (isForCompress && !!this.isCompressionEnabled && Type.isString(accept)) {
            if (!this.hasHeader('Vary')) {
                this.addHeader('Vary', 'Accept-Encoding');
            }
            if (accept.indexOf('gzip') > -1) {
                return new Promise(function (resolve, reject) {
                    zlib.gzip(response, function (err, data) {
                        if (err) {
                            return reject(err);
                        }
                        that.isCompressed = true;
                        that.addHeader('Content-Encoding', 'gzip');
                        resolve(data);
                    });
                });
            } else if (accept.indexOf('deflate') > -1) {
                return new Promise(function (resolve, reject) {
                    zlib.deflate(response, function (err, data) {
                        if (err) {
                            return reject(err);
                        }
                        that.isCompressed = true;
                        that.addHeader('Content-Encoding', 'deflate');
                        resolve(data);
                    });
                });
            }
        }

        return response;
    }
686062
function FileKeyInfo(file) {
  this.file = file

  this.getKeyInfo = function(key, prefix) {
    prefix = prefix || ''
    prefix = prefix ? prefix + ':' : prefix
    return "<" + prefix + "X509Data></" + prefix + "X509Data>"
  }

  this.getKey = function(keyInfo) {
    return fs.readFileSync(this.file)
  }
}
200068
private FileSystem newZipFileSystem(final File file) throws IOException {

        final Map<String, String> env = new HashMap<>();
        env.put("create", "true");
        return newFileSystem(URI.create("jar:" + file.toURI()), env);
    }
900485
public CompressionCodec getCodec(Path file) {
    CompressionCodec result = null;
    if (codecs != null) {
      String filename = file.getName();
      String reversedFilename = new StringBuffer(filename).reverse().toString();
      SortedMap<String, CompressionCodec> subMap = 
        codecs.headMap(reversedFilename);
      if (!subMap.isEmpty()) {
        String potentialSuffix = subMap.lastKey();
        if (reversedFilename.startsWith(potentialSuffix)) {
          result = codecs.get(potentialSuffix);
        }
      }
    }
    return result;
  }