pinch 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +16 -15
- data/lib/pinch.rb +1 -1
- data/lib/pinch_response.rb +18 -7
- data/spec/pinch_spec.rb +6 -6
- metadata +25 -36
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 030d2274d6753a92063e30f52381861e0ac69668
|
4
|
+
data.tar.gz: 3f3dcec53eae2f7aa575848f0d69ea2ff1059ec4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5c1921fde2cb1f4531664a7bfa11b6fb4dadd3f35511bf3e7efa91efdcceb3c3f33b9ce6292dffa98c5fdad361f5cc3bf3192415d1690edd7c1e687adf8316e
|
7
|
+
data.tar.gz: 18f2ed70982f7e3f85c4b4157310229bd2bda5798e2abec73eb73c43ba33a113c72e788a0d6817516908e8f17e81029f856621765e54148c1d571414b1f8e8e1
|
data/README.rdoc
CHANGED
@@ -27,26 +27,27 @@ The specs currently blows up on MagLev.
|
|
27
27
|
|
28
28
|
require 'pinch'
|
29
29
|
|
30
|
-
data = Pinch.get 'http://peterhellberg.github.
|
30
|
+
data = Pinch.get 'http://peterhellberg.github.io/pinch/test.zip', 'data.json'
|
31
31
|
|
32
32
|
puts data
|
33
33
|
|
34
|
-
|
35
|
-
AWS S3 storage verifies url signature against HTTP verb, therefore requiring different pre-signed urls for HEAD and GET requests. Patch extends Pinch gem to accept hash or 2 urls, allowing to fetch items stored in zip archives on S3.
|
34
|
+
=== Amazon S3 storage with pre-signed urls
|
36
35
|
|
37
|
-
|
36
|
+
AWS S3 storage verifies url signature against HTTP verb, therefore
|
37
|
+
requiring different pre-signed urls for HEAD and GET requests.
|
38
|
+
Patch extends Pinch gem to accept hash or 2 urls, allowing to fetch
|
39
|
+
items stored in zip archives on S3.
|
38
40
|
|
39
|
-
require '
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
head_ticket = bucket.key('test.zip').head
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
data=Pinch.get({:head => head_url, :get => get_url},'data.json')
|
41
|
+
require 'pinch'
|
42
|
+
require 'right_aws'
|
43
|
+
|
44
|
+
s3 = RightAws::S3Generator.new('...','...')
|
45
|
+
|
46
|
+
bucket = s3.bucket('my-bucket')
|
47
|
+
head_ticket = bucket.key('test.zip').head
|
48
|
+
get_ticket = bucket.key('test.zip').get
|
49
|
+
|
50
|
+
data=Pinch.get({:head => head_url, :get => get_url},'data.json')
|
50
51
|
|
51
52
|
== LICENSE
|
52
53
|
|
data/lib/pinch.rb
CHANGED
data/lib/pinch_response.rb
CHANGED
@@ -1,33 +1,44 @@
|
|
1
1
|
# This class only implements read_body
|
2
2
|
# The rest can be implemented when required
|
3
|
+
#
|
3
4
|
class PinchResponse
|
5
|
+
##
|
6
|
+
# Prepare pinch response
|
7
|
+
#
|
4
8
|
def initialize(http_response)
|
5
9
|
@http_response = http_response
|
6
|
-
@zstream
|
7
|
-
@first_chunk
|
10
|
+
@zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
|
11
|
+
@first_chunk = true
|
8
12
|
end
|
9
13
|
|
14
|
+
##
|
15
|
+
# Read the body of the HTTP response
|
16
|
+
#
|
10
17
|
def read_body
|
11
18
|
if block_given?
|
12
19
|
@http_response.read_body do |chunk|
|
13
20
|
if @first_chunk
|
14
21
|
local_file_header = chunk.unpack('VvvvvvVVVvv')
|
15
|
-
@offset_start = 30+local_file_header[9]+local_file_header[10]
|
16
|
-
@compressed = (local_file_header[3] != 0)
|
17
|
-
@length = @compressed ? local_file_header[7] : local_file_header[8]
|
18
22
|
|
23
|
+
@offset_start = 30+local_file_header[9]+local_file_header[10]
|
24
|
+
@compressed = (local_file_header[3] != 0)
|
25
|
+
@length = @compressed ? local_file_header[7] : local_file_header[8]
|
19
26
|
@cursor_start = @offset_start
|
20
|
-
@to_be_read
|
21
|
-
|
27
|
+
@to_be_read = @length
|
28
|
+
|
29
|
+
@first_chunk = false
|
22
30
|
end
|
23
31
|
|
24
32
|
cursor_start = [@cursor_start, 0].max
|
25
33
|
cursor_end = [@to_be_read, chunk.length].min
|
34
|
+
|
26
35
|
data = chunk[cursor_start, cursor_end]
|
36
|
+
|
27
37
|
@cursor_start -= chunk.length
|
28
38
|
|
29
39
|
if data
|
30
40
|
@to_be_read -= data.length
|
41
|
+
|
31
42
|
if @compressed
|
32
43
|
yield @zstream.inflate(data)
|
33
44
|
else
|
data/spec/pinch_spec.rb
CHANGED
@@ -24,7 +24,7 @@ require 'vcr'
|
|
24
24
|
VCR.configure do |c|
|
25
25
|
c.allow_http_connections_when_no_cassette = true
|
26
26
|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
27
|
-
c.hook_into :
|
27
|
+
c.hook_into :webmock
|
28
28
|
end
|
29
29
|
|
30
30
|
require File.dirname(__FILE__) + '/../lib/pinch'
|
@@ -69,7 +69,7 @@ describe Pinch do
|
|
69
69
|
|
70
70
|
describe "when calling get on the example ZIP file" do
|
71
71
|
before do
|
72
|
-
@url = 'http://peterhellberg.github.
|
72
|
+
@url = 'http://peterhellberg.github.io/pinch/test.zip'
|
73
73
|
@file = 'data.json'
|
74
74
|
@data = "{\"gem\":\"pinch\",\"authors\":[\"Peter Hellberg\",\"Edward Patel\"],\"github_url\":\"https://github.com/peterhellberg/pinch\"}\n"
|
75
75
|
end
|
@@ -97,7 +97,7 @@ describe Pinch do
|
|
97
97
|
|
98
98
|
it "should retrieve the contents of the file data.json when passed a HTTPS url" do
|
99
99
|
VCR.use_cassette('ssl_test') do
|
100
|
-
@url = 'https://dl.
|
100
|
+
@url = 'https://dl.dropboxusercontent.com/u/2230186/pinch_test.zip'
|
101
101
|
|
102
102
|
data = Pinch.get @url, @file
|
103
103
|
data.must_equal @data
|
@@ -111,10 +111,10 @@ describe Pinch do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
describe "when calling get on the example ZIP file behind HTTP Basic Authentication" do
|
116
116
|
before do
|
117
|
-
@url = 'http://
|
117
|
+
@url = 'http://assets.c7.se/data/pinch/auth/pinch_test.zip'
|
118
118
|
@file = 'data.json'
|
119
119
|
@data = "{\"gem\":\"pinch\",\"authors\":[\"Peter Hellberg\",\"Edward Patel\"],\"github_url\":\"https://github.com/peterhellberg/pinch\"}\n"
|
120
120
|
end
|
@@ -149,7 +149,7 @@ describe Pinch do
|
|
149
149
|
|
150
150
|
describe "Pinch.content_length" do
|
151
151
|
before do
|
152
|
-
@url = 'http://peterhellberg.github.
|
152
|
+
@url = 'http://peterhellberg.github.io/pinch/test.zip'
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should return the size of the ZIP file" do
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Peter Hellberg
|
@@ -10,56 +9,50 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2014-01-04 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: minitest
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- - ~>
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
20
|
+
version: '5.2'
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- - ~>
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
27
|
+
version: '5.2'
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
|
-
name:
|
29
|
+
name: webmock
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- - ~>
|
32
|
+
- - "~>"
|
37
33
|
- !ruby/object:Gem::Version
|
38
|
-
version: '1.
|
34
|
+
version: '1.16'
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- - ~>
|
39
|
+
- - "~>"
|
45
40
|
- !ruby/object:Gem::Version
|
46
|
-
version: '1.
|
41
|
+
version: '1.16'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: vcr
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- - ~>
|
46
|
+
- - "~>"
|
53
47
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
48
|
+
version: '2.8'
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- - ~>
|
53
|
+
- - "~>"
|
61
54
|
- !ruby/object:Gem::Version
|
62
|
-
version: '2.
|
55
|
+
version: '2.8'
|
63
56
|
description: Pinch makes it possible to download a specific file from within a ZIP
|
64
57
|
file over HTTP 1.1.
|
65
58
|
email: peter@c7.se
|
@@ -69,44 +62,40 @@ extra_rdoc_files:
|
|
69
62
|
- README.rdoc
|
70
63
|
- MIT-LICENSE
|
71
64
|
files:
|
72
|
-
-
|
73
|
-
- lib/pinch_response.rb
|
65
|
+
- ".gemtest"
|
74
66
|
- MIT-LICENSE
|
75
67
|
- README.rdoc
|
76
68
|
- Rakefile
|
77
|
-
- .
|
69
|
+
- lib/pinch.rb
|
70
|
+
- lib/pinch_response.rb
|
78
71
|
- spec/pinch_spec.rb
|
79
72
|
homepage: http://peterhellberg.github.com/pinch/
|
80
73
|
licenses:
|
81
74
|
- MIT-LICENSE
|
75
|
+
metadata: {}
|
82
76
|
post_install_message:
|
83
77
|
rdoc_options:
|
84
|
-
- --main
|
78
|
+
- "--main"
|
85
79
|
- README.rdoc
|
86
|
-
- --charset=UTF-8
|
80
|
+
- "--charset=UTF-8"
|
87
81
|
require_paths:
|
88
82
|
- lib
|
89
83
|
- lib
|
90
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
-
none: false
|
92
85
|
requirements:
|
93
|
-
- -
|
86
|
+
- - ">="
|
94
87
|
- !ruby/object:Gem::Version
|
95
88
|
version: 1.8.7
|
96
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
90
|
requirements:
|
99
|
-
- -
|
91
|
+
- - ">="
|
100
92
|
- !ruby/object:Gem::Version
|
101
93
|
version: '0'
|
102
|
-
segments:
|
103
|
-
- 0
|
104
|
-
hash: 752809128111839856
|
105
94
|
requirements: []
|
106
95
|
rubyforge_project:
|
107
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.2.0.rc.1
|
108
97
|
signing_key:
|
109
|
-
specification_version:
|
98
|
+
specification_version: 4
|
110
99
|
summary: Retrieve a file from inside a zip file, over the network!
|
111
100
|
test_files:
|
112
101
|
- spec/pinch_spec.rb
|