Class: Ngzip::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/ngzip/builder.rb

Overview

The manifest builder based on the file list

Constant Summary collapse

BUFFER_SIZE =
8 * 1024

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.encode(string) ⇒ Object

Public: Encode the string

Returns the encoded string using URL escape formatting



56
57
58
# File 'lib/ngzip/builder.rb', line 56

def self.encode(string)
  ERB::Util.url_encode(string)
end

Instance Method Details

#build(files, options = {}) ⇒ Object

Public: Build the files manifest for mod_zip, see wiki.nginx.org/NginxNgxZip for the specs.

files - An Array of absolute file path elements options - The options, see below

Returns a line for each file separated by n

The following options are available:

crc:         Enable or disable CRC-32 checksums
crc_cache:   Allows for provided cached CRC-32 checksums in a hash where the key is the file path
base_dir:    Use this as root for the relative pathes in the archive, keep all directories below


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ngzip/builder.rb', line 26

def build(files, options = {})
  settings = { crc: true }
  settings.merge! options

  list = file_list(files)
  prefix = options[:base_dir] || detect_common_prefix(list)
  prefix += '/' unless prefix.end_with?('/')
  list.map do |f|
    format(
      '%<crc>s %<size>d %<url>s %<name>s',
      {
        crc: compute_crc32(f, settings),
        size: File.size(f).to_i,
        url: Builder.encode(f),
        name: f.gsub(prefix, '')
      }
    )
  end.join("\n")
end

#headerObject

Public: Get the special header to signal the mod_zip

Returns the header as a string “key: value”



49
50
51
# File 'lib/ngzip/builder.rb', line 49

def header
  'X-Archive-Files: zip'
end