ngzip 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e20636d23b8e7ba30af726b7a530f96f31eb636a
4
+ data.tar.gz: ed999e168b1c77b6942cb2cb6f118a5a936fe434
5
+ SHA512:
6
+ metadata.gz: 70d66540ec58ff16e08321b26b998e303c765f3aaa057f58e9956cd5922c1e39869ce1c2d75b5a5db01952a91089661470fca66bc069fe0d540b15e60c9743fc
7
+ data.tar.gz: 769e82edd41c5029b2eef0be5dbc89fcdaaae0f5b2570902cbe3bc71b601d3145dde48b86bfebfe4839d785d4aece3a8b62fd74d7ae079cc1d5ba1d7bed882d6
@@ -1,8 +1,11 @@
1
+ ### 1.0.7 (2017-10-20)
2
+
3
+ * Fixed an issue with '?' encoding
4
+
1
5
  ### 1.0.6 (2013-12-12)
2
6
 
3
7
  * Fixed a regression from 1.0.5 where directories were included due to the changed pattern
4
8
 
5
-
6
9
  ### 1.0.5 (2013-12-12)
7
10
 
8
11
  * Fixed issue #2 (files without extensions being ignored)
@@ -26,4 +29,3 @@
26
29
  ### 1.0.0 (2013-07-14)
27
30
 
28
31
  * Initial public release
29
-
@@ -1,4 +1,5 @@
1
1
  Copyright (c) 2013 ncode gmbh
2
+ Copyright (c) 2017 CargoServer AG
2
3
 
3
4
  MIT License
4
5
 
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
  In a controller
23
23
 
24
24
  ```ruby
25
- b = Nginx::Builder.new()
25
+ b = Ngzip::Builder.new()
26
26
  response.headers['X-Archive-Files'] = 'zip'
27
27
  render :text => b.build(["/data/test/Report.pdf", "/data/test/LargeArchive.tar"])
28
28
  ```
@@ -67,6 +67,6 @@ fetch the actual file data and would support any location type (even proxied).
67
67
  ## License
68
68
 
69
69
  Copyright (c) 2013, ncode gmbh. All Rights Reserved.
70
+ Copyright (c) 2017, CargoServer AG. All Rights Reserved.
70
71
 
71
72
  This project is licenced under the [MIT License](LICENSE.txt).
72
-
@@ -2,18 +2,16 @@ require 'zlib'
2
2
  require 'uri'
3
3
 
4
4
  module Ngzip
5
-
6
5
  class Builder
7
-
8
6
  BUFFER_SIZE = 8 * 1024
9
-
7
+
10
8
  # Public: Build the files manifest for mod_zip, see http://wiki.nginx.org/NginxNgxZip for the specs.
11
- #
9
+ #
12
10
  # files - An Array of absolute file path elements
13
11
  # options - The options, see below
14
- #
12
+ #
15
13
  # Returns a line for each file separated by \n
16
- #
14
+ #
17
15
  # The following options are available:
18
16
  # :crc => Enable or disable CRC-32 checksums
19
17
  # :crc_cache => Allows for provided cached CRC-32 checksums in a hash where the key is the file path
@@ -21,7 +19,7 @@ module Ngzip
21
19
  def build(files, options = {})
22
20
  settings = {:crc => true}
23
21
  settings.merge! options
24
-
22
+
25
23
  list = file_list(files)
26
24
  prefix = options[:base_dir] || detect_common_prefix(list)
27
25
  prefix += '/' unless prefix.end_with?('/')
@@ -36,26 +34,25 @@ module Ngzip
36
34
  end
37
35
 
38
36
  # Public: Get the special header to signal the mod_zip
39
- #
37
+ #
40
38
  # Returns the header as a string "key: value"
41
39
  def header()
42
40
  "X-Archive-Files: zip"
43
41
  end
44
-
45
-
46
- # Public: Encode the string
42
+
43
+ # Public: Encode the string
47
44
  #
48
45
  # Returns the encoded string using URL escape formatting
49
46
  def self.encode(string)
50
- URI.encode(string).sub('+', "%2B")
47
+ URI.encode(string).gsub('+', '%2B').gsub('?', '%3F')
51
48
  end
52
-
49
+
53
50
  private
54
-
51
+
55
52
  # Internal: Compute a common prefix from a list of path elements
56
- #
53
+ #
57
54
  # list - The list of file path elements
58
- #
55
+ #
59
56
  # Returns a common prefix
60
57
  def detect_common_prefix(list)
61
58
  if list.size == 1
@@ -69,9 +66,9 @@ module Ngzip
69
66
  end
70
67
  prefix
71
68
  end
72
-
69
+
73
70
  # Internal: Compute the file list by expanding directories
74
- #
71
+ #
75
72
  def file_list(files)
76
73
  Array(files).map do |e|
77
74
  if File.directory?(e)
@@ -81,33 +78,30 @@ module Ngzip
81
78
  end
82
79
  end.flatten
83
80
  end
84
-
85
-
86
- # Internal: Compute the CRC-32 checksum for a file unless the settings
81
+
82
+ # Internal: Compute the CRC-32 checksum for a file unless the settings
87
83
  # disable the computation (:crc => false) and this method returns "-"
88
- #
84
+ #
89
85
  # file - The full path to the file
90
86
  # settings - The settings hash
91
- #
87
+ #
92
88
  # Returns a hex string
93
89
  def compute_crc32(file, settings)
94
90
  return '-' unless settings[:crc]
95
-
91
+
96
92
  # honor the cache
97
93
  if settings[:crc_cache] && settings[:crc_cache][file]
98
94
  return settings[:crc_cache][file]
99
95
  end
100
-
96
+
101
97
  # read using a buffer, we might operate on large files!
102
98
  crc32 = 0
103
99
  File.open(file,'rb') do |f|
104
100
  while buffer = f.read(BUFFER_SIZE) do
105
- crc32 = Zlib.crc32(buffer, crc32)
101
+ crc32 = Zlib.crc32(buffer, crc32)
106
102
  end
107
103
  end
108
104
  crc32.to_s(16)
109
105
  end
110
-
111
106
  end
112
-
113
- end
107
+ end
@@ -1,3 +1,3 @@
1
1
  module Ngzip
2
- VERSION = "1.0.6"
2
+ VERSION = '1.0.7'.freeze
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "ngzip"
8
8
  spec.version = Ngzip::VERSION
9
9
  spec.authors = ["dup2"]
10
- spec.email = ["zarkov@ncode.ch"]
10
+ spec.email = ["zarkov@cargoserver.ch"]
11
11
  spec.description = %q{Provides a nginx mod_zip compatible file manifest for streaming support.
12
12
  See http://wiki.nginx.org/NginxNgxZip for the nginx module.}
13
13
  spec.summary = %q{Provides a nginx mod_zip compatible file manifest for streaming support}
@@ -0,0 +1 @@
1
+ Tyrell Corp.
@@ -1,16 +1,17 @@
1
1
  require_relative "../../test_helper"
2
2
  require 'uri'
3
+ require 'pathname'
3
4
 
4
5
  describe Ngzip do
5
6
 
6
7
  it 'must support the static method :build' do
7
8
  Ngzip.respond_to?(:build).must_equal true
8
- end
9
+ end
9
10
 
10
11
  end
11
12
 
12
13
  describe Ngzip::Builder do
13
-
14
+
14
15
  let(:builder) {Ngzip::Builder.new()}
15
16
  let(:lorem) {File.expand_path('../../../data/a/lorem.txt', __FILE__)}
16
17
  let(:ipsum) {File.expand_path('../../../data/a/ipsum.txt', __FILE__)}
@@ -21,46 +22,47 @@ describe Ngzip::Builder do
21
22
  let(:cargo) {File.expand_path('../../../data/b/Cargo.png', __FILE__)}
22
23
  let(:sit) {File.expand_path('../../../data/sit.txt', __FILE__)}
23
24
  let(:a) {File.expand_path('../../../data/a', __FILE__)}
24
-
25
+ let(:questions) { File.expand_path('../../../data/c/questions?', __FILE__) }
26
+
25
27
  it 'must be defined' do
26
28
  Ngzip::Builder.wont_be_nil
27
- end
28
-
29
+ end
30
+
29
31
  it 'must be a class we can call :new on' do
30
32
  Ngzip::Builder.new().wont_be_nil
31
33
  end
32
-
34
+
33
35
  it 'must respond to :build' do
34
36
  builder.respond_to?(:build).must_equal true
35
37
  end
36
-
38
+
37
39
  describe "with CRC-32 checksums disabled" do
38
40
  let(:options) { {:crc => false}}
39
-
41
+
40
42
  it 'must return a correct list for one file' do
41
43
  expected = "- 446 #{lorem} lorem.txt"
42
- builder.build(lorem, options).must_equal expected
43
- end
44
+ builder.build(lorem, options).must_equal expected
45
+ end
44
46
  end
45
-
47
+
46
48
  describe "with CRC-32 checksums enabled" do
47
49
  let(:options) { {:crc => true}}
48
-
50
+
49
51
  it 'must return a correct list for one file with a checksum' do
50
52
  expected = "8f92322f 446 #{lorem} lorem.txt"
51
53
  builder.build(lorem, options).must_equal expected
52
54
  end
53
-
55
+
54
56
  it 'must return a correct list for one binary file with a checksum' do
55
57
  expected = "b2f4655b 11550 #{cargo} Cargo.png"
56
58
  builder.build(cargo, options).must_equal expected
57
59
  end
58
-
60
+
59
61
  it 'must escape the path name' do
60
62
  expected = "8f92322f 446 #{URI.escape(whitespaced)} A filename with whitespace.txt"
61
63
  builder.build(whitespaced, options).must_equal expected
62
64
  end
63
-
65
+
64
66
  it 'must return a correct list for all files in a directory' do
65
67
  expected = "8f92322f 446 #{URI.escape(whitespaced)} A filename with whitespace.txt"
66
68
  expected << "\n8f92322f 446 #{my_file} d/my_file.txt"
@@ -69,7 +71,7 @@ describe Ngzip::Builder do
69
71
  expected << "\n8f92322f 446 #{lorem} lorem.txt"
70
72
  builder.build(a,options).must_equal expected
71
73
  end
72
-
74
+
73
75
  it 'must allow to mix files and directories' do
74
76
  expected = "8f92322f 446 #{URI.escape(whitespaced)} a/A filename with whitespace.txt"
75
77
  expected << "\n8f92322f 446 #{my_file} a/d/my_file.txt"
@@ -77,9 +79,9 @@ describe Ngzip::Builder do
77
79
  expected << "\n8f92322f 446 #{ipsum} a/ipsum.txt"
78
80
  expected << "\n8f92322f 446 #{lorem} a/lorem.txt"
79
81
  expected << "\nf7c0867d 1342 #{sit} sit.txt"
80
- builder.build([a,sit], options).must_equal expected
82
+ builder.build([a,sit], options).must_equal expected
81
83
  end
82
-
84
+
83
85
  it 'must preserve directory names' do
84
86
  expected = [
85
87
  "8f92322f 446 #{lorem} a/lorem.txt",
@@ -88,41 +90,45 @@ describe Ngzip::Builder do
88
90
  ].join("\n")
89
91
  builder.build([lorem,ipsum,cargo], options).must_equal expected
90
92
  end
91
-
93
+
92
94
  it 'must honor the CRC cache' do
93
95
  invalid_but_cached = "781aaabcc124"
94
96
  expected = "#{invalid_but_cached} 446 #{lorem} lorem.txt"
95
97
  builder.build(lorem, options.merge(:crc_cache => {lorem => invalid_but_cached})).must_equal expected
96
98
  end
97
-
99
+
98
100
  it 'must remove common directories by default' do
99
101
  pathes = builder.build([lorem, ipsum]).split("\n").map{|line| line.split.last}
100
102
  expected = ["lorem.txt", "ipsum.txt"]
101
103
  pathes.must_equal expected
102
104
  end
103
-
105
+
104
106
  it 'must keep common directories if :base_dir is provided' do
105
107
  options = {:base_dir => Pathname.new(lorem).parent.parent.to_s}
106
108
  pathes = builder.build([lorem, ipsum], options).split("\n").map{|line| line.split.last}
107
109
  expected = ["a/lorem.txt", "a/ipsum.txt"]
108
110
  pathes.must_equal expected
109
111
  end
110
-
112
+
111
113
  it 'must cope with a trailing / in the :base_dir' do
112
114
  options = {:base_dir => Pathname.new(lorem).parent.parent.to_s + '/'}
113
115
  pathes = builder.build([lorem, ipsum], options).split("\n").map{|line| line.split.last}
114
116
  expected = ["a/lorem.txt", "a/ipsum.txt"]
115
- pathes.must_equal expected
117
+ pathes.must_equal expected
116
118
  end
117
-
119
+
118
120
  it 'must correctly encode filenames with a "+"' do
119
121
  options = {}
120
- name = File.join(Pathname.new(plused).parent.to_s, 'A%20filename%20with%20space%20and%20%2B%20in%20it.txt')
122
+ name = File.join(Pathname.new(plused).parent.to_s, 'A%20filename%20with%20space%20and%20%2B%20in%20it.txt')
121
123
  expected = "8f92322f 446 #{name} A filename with space and + in it.txt"
122
124
  builder.build([plused], options).must_equal expected
123
125
  end
124
-
125
-
126
+
127
+ it 'must correctly encode the "?" character' do
128
+ name = File.join(Pathname.new(questions).parent.to_s, 'questions%3F/test.txt')
129
+ expected = "f03102f5 13 #{name} test.txt"
130
+
131
+ builder.build([File.join(questions, 'test.txt')]).must_equal expected
132
+ end
126
133
  end
127
-
128
134
  end
metadata CHANGED
@@ -1,58 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngzip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
5
- prerelease:
4
+ version: 1.0.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - dup2
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-12 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.3'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- description: ! "Provides a nginx mod_zip compatible file manifest for streaming support.\n
47
- \ See http://wiki.nginx.org/NginxNgxZip for the nginx module."
41
+ description: |-
42
+ Provides a nginx mod_zip compatible file manifest for streaming support.
43
+ See http://wiki.nginx.org/NginxNgxZip for the nginx module.
48
44
  email:
49
- - zarkov@ncode.ch
45
+ - zarkov@cargoserver.ch
50
46
  executables: []
51
47
  extensions: []
52
48
  extra_rdoc_files: []
53
49
  files:
54
- - .gitignore
55
- - .rvmrc
50
+ - ".gitignore"
56
51
  - CHANGELOG.md
57
52
  - Gemfile
58
53
  - LICENSE.txt
@@ -70,6 +65,7 @@ files:
70
65
  - test/data/b/Cargo.png
71
66
  - test/data/b/dolor.txt
72
67
  - test/data/c/A filename with space and + in it.txt
68
+ - test/data/c/questions?/test.txt
73
69
  - test/data/sit.txt
74
70
  - test/lib/ngzip/builder_test.rb
75
71
  - test/lib/ngzip/version_test.rb
@@ -77,33 +73,26 @@ files:
77
73
  homepage: https://github.com/cargoserver/ngzip
78
74
  licenses:
79
75
  - MIT
76
+ metadata: {}
80
77
  post_install_message:
81
78
  rdoc_options: []
82
79
  require_paths:
83
80
  - lib
84
81
  required_ruby_version: !ruby/object:Gem::Requirement
85
- none: false
86
82
  requirements:
87
- - - ! '>='
83
+ - - ">="
88
84
  - !ruby/object:Gem::Version
89
85
  version: '0'
90
- segments:
91
- - 0
92
- hash: 4602707169932349817
93
86
  required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
87
  requirements:
96
- - - ! '>='
88
+ - - ">="
97
89
  - !ruby/object:Gem::Version
98
90
  version: '0'
99
- segments:
100
- - 0
101
- hash: 4602707169932349817
102
91
  requirements: []
103
92
  rubyforge_project:
104
- rubygems_version: 1.8.25
93
+ rubygems_version: 2.6.13
105
94
  signing_key:
106
- specification_version: 3
95
+ specification_version: 4
107
96
  summary: Provides a nginx mod_zip compatible file manifest for streaming support
108
97
  test_files:
109
98
  - test/data/a/A filename with whitespace.txt
@@ -114,6 +103,7 @@ test_files:
114
103
  - test/data/b/Cargo.png
115
104
  - test/data/b/dolor.txt
116
105
  - test/data/c/A filename with space and + in it.txt
106
+ - test/data/c/questions?/test.txt
117
107
  - test/data/sit.txt
118
108
  - test/lib/ngzip/builder_test.rb
119
109
  - test/lib/ngzip/version_test.rb
data/.rvmrc DELETED
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
- # Only full ruby name is supported here, for short names use:
8
- # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p392@ngzip"
10
-
11
- # Uncomment the following lines if you want to verify rvm version per project
12
- # rvmrc_rvm_version="1.18.14 (version)" # 1.10.1 seams as a safe start
13
- # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
- # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
- # return 1
16
- # }
17
-
18
- # First we attempt to load the desired environment directly from the environment
19
- # file. This is very fast and efficient compared to running through the entire
20
- # CLI and selector. If you want feedback on which environment was used then
21
- # insert the word 'use' after --create as this triggers verbose mode.
22
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
- then
25
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
- [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
- \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
- else
29
- # If the environment file has not yet been created, use the RVM CLI to select.
30
- rvm --create "$environment_id" || {
31
- echo "Failed to create RVM environment '${environment_id}'."
32
- return 1
33
- }
34
- fi
35
-
36
- # If you use bundler, this might be useful to you:
37
- # if [[ -s Gemfile ]] && {
38
- # ! builtin command -v bundle >/dev/null ||
39
- # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
- # }
41
- # then
42
- # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
- # gem install bundler
44
- # fi
45
- # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
- # then
47
- # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
- # fi