pinch 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/pinch.rb +6 -2
  2. data/spec/pinch_spec.rb +19 -10
  3. metadata +3 -3
@@ -3,7 +3,7 @@ require 'net/http'
3
3
  require 'zlib'
4
4
 
5
5
  class Pinch
6
- VERSION = "0.0.1"
6
+ VERSION = "0.0.2"
7
7
 
8
8
  attr_reader :uri
9
9
  attr_reader :file_name
@@ -76,8 +76,12 @@ class Pinch
76
76
  file_data = res.body[30+local_file_header[9]+local_file_header[10]..-1]
77
77
 
78
78
  if local_file_header[3] == 0
79
- raise NotImplementedError, "Unable to read uncompressed ZIP files for now"
79
+ # Uncompressed file
80
+ offset = 30+local_file_header[9]+local_file_header[10]
81
+ res.body[offset..(offset+local_file_header[8]-1)]
80
82
  else
83
+ # Compressed file
84
+ file_data = res.body[30+local_file_header[9]+local_file_header[10]..-1]
81
85
  Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(file_data)
82
86
  end
83
87
  end
@@ -5,20 +5,29 @@ require 'minitest/spec'
5
5
  require File.dirname(__FILE__) + '/../lib/pinch'
6
6
 
7
7
  describe Pinch do
8
- describe "when calling get" do
8
+ describe "when calling get on a compressed zip file" do
9
+ before do
10
+ @url = 'http://ftp.sunet.se/pub/lang/smalltalk/Squeak/current_stable/Squeak3.8-6665-full.zip'
11
+ @file = 'ReadMe.txt'
12
+ end
13
+
9
14
  it "should return the contents of the file" do
10
- url = 'http://ftp.sunet.se/pub/lang/smalltalk/Squeak/current_stable/Squeak3.8-6665-full.zip'
11
- file = 'ReadMe.txt'
12
- data = Pinch.get url, file
15
+ data = Pinch.get @url, @file
13
16
  data.must_match /Morphic graphics architecture/
17
+ data.size.must_equal 26424
18
+ end
19
+ end
20
+
21
+ describe "when calling get on a zip file that is not compressed" do
22
+ before do
23
+ @url = 'http://memention.com/ericjohnson-canabalt-ios-ef43b7d.zip'
24
+ @file = 'ericjohnson-canabalt-ios-ef43b7d/README.TXT'
14
25
  end
15
26
 
16
- it "should not pinch from a zip file that is not deflated (for now)" do
17
- lambda {
18
- url = 'http://memention.com/ericjohnson-canabalt-ios-ef43b7d.zip'
19
- file = 'ericjohnson-canabalt-ios-ef43b7d/README.TXT'
20
- data = Pinch.get url, file
21
- }.must_raise NotImplementedError
27
+ it "should return the contents of the file" do
28
+ data = Pinch.get @url, @file
29
+ data.must_match /Daring Escape/
30
+ data.size.must_equal 2288
22
31
  end
23
32
  end
24
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: minitest
18
- requirement: &2156678820 !ruby/object:Gem::Requirement
18
+ requirement: &2153205580 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: '0'
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *2156678820
26
+ version_requirements: *2153205580
27
27
  description: Pinch makes it possible to download a specific file from within a ZIP
28
28
  file over HTTP 1.1.
29
29
  email: peter@c7.se