shuck 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -13,10 +13,17 @@ GEM
13
13
  mime-types
14
14
  xml-simple
15
15
  builder (2.1.2)
16
+ columnize (0.3.2)
17
+ linecache (0.43)
16
18
  mime-types (1.16)
17
19
  right_aws (2.0.0)
18
20
  right_http_connection (>= 1.2.1)
19
21
  right_http_connection (1.2.4)
22
+ ruby-debug (0.10.4)
23
+ columnize (>= 0.1)
24
+ ruby-debug-base (~> 0.10.4.0)
25
+ ruby-debug-base (0.10.4)
26
+ linecache (>= 0.3)
20
27
  thor (0.14.4)
21
28
  xml-simple (1.0.12)
22
29
 
@@ -28,5 +35,6 @@ DEPENDENCIES
28
35
  builder
29
36
  bundler (>= 1.0.0)
30
37
  right_aws
38
+ ruby-debug
31
39
  shuck!
32
40
  thor
@@ -36,13 +36,14 @@ module Shuck
36
36
  @bucket_hash[bucket] = bucket_obj
37
37
  end
38
38
 
39
- def get_object(bucket,object)
39
+ def get_object(bucket,object, request)
40
40
  begin
41
41
  real_obj = S3Object.new
42
42
  obj_root = File.join(@root,bucket,object,SHUCK_METADATA_DIR)
43
43
  metadata = YAML.parse(File.open(File.join(obj_root,"metadata"),'rb').read)
44
44
  real_obj.name = object
45
45
  real_obj.md5 = metadata[:md5].value
46
+ real_obj.content_type = metadata[:content_type] ? metadata[:content_type].value : "application/octet-stream"
46
47
  real_obj.io = File.open(File.join(obj_root,"content"),'rb')
47
48
  return real_obj
48
49
  rescue
@@ -72,14 +73,17 @@ module Shuck
72
73
  md5 << chunk
73
74
  end
74
75
  end
76
+
75
77
  metadata_struct = {}
76
78
  metadata_struct[:md5] = md5.hexdigest
79
+ metadata_struct[:content_type] = request.header["content-type"].first
77
80
 
78
81
  File.open(metadata,'w') do |f|
79
82
  f << YAML::dump(metadata_struct)
80
83
  end
81
84
  obj = S3Object.new
82
85
  obj.md5 = metadata_struct[:md5]
86
+ obj.content_type = metadata_struct[:content_type]
83
87
  return obj
84
88
  rescue
85
89
  puts $!
@@ -1,5 +1,5 @@
1
1
  module Shuck
2
2
  class S3Object
3
- attr_accessor :name,:size,:creation_date,:md5,:io
3
+ attr_accessor :name,:size,:creation_date,:md5,:io,:content_type
4
4
  end
5
5
  end
data/lib/shuck/server.rb CHANGED
@@ -47,12 +47,37 @@ module Shuck
47
47
  end
48
48
  else
49
49
  object = elems[1,elems.size].join('/')
50
- real_obj = @store.get_object(bucket,object)
50
+ real_obj = @store.get_object(bucket,object, request)
51
+
51
52
  if real_obj
52
53
  response.status = 200
53
- response['Content-Type'] = "application/octet-stream"
54
- response['Content-Length'] = File.size(real_obj.io)
54
+ response['Content-Type'] = real_obj.content_type
55
+ content_length = File::Stat.new(real_obj.io.path).size
55
56
  response['Etag'] = real_obj.md5
57
+ response['Accept-Ranges'] = "bytes"
58
+
59
+ # Added Range Query support
60
+ if range = request.header["range"].first
61
+ response.status = 206
62
+ if range =~ /bytes=(\d*)-(\d*)/
63
+ start = $1.to_i
64
+ finish = $2.to_i
65
+ finish_str = ""
66
+ if finish == 0
67
+ finish = content_length - 1
68
+ finish_str = "#{finish}"
69
+ else
70
+ finish_str = finish.to_s
71
+ end
72
+
73
+ bytes_to_read = finish - start + 1
74
+ response['Content-Range'] = "bytes #{start}-#{finish_str}/#{content_length}"
75
+ real_obj.io.pos = start
76
+ response.body = real_obj.io.read(bytes_to_read)
77
+ return
78
+ end
79
+ end
80
+ response['Content-Length'] = File::Stat.new(real_obj.io.path).size
56
81
  response.body = real_obj.io
57
82
  else
58
83
  response.status = 404
data/lib/shuck/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Shuck
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/shuck.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_development_dependency "bundler", ">= 1.0.0"
18
18
  s.add_development_dependency "aws-s3"
19
19
  s.add_development_dependency "right_aws"
20
+ s.add_development_dependency "ruby-debug"
20
21
  s.add_dependency "thor"
21
22
  s.add_dependency "builder"
22
23
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Curtis Spencer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-19 00:00:00 -08:00
17
+ date: 2011-06-06 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -59,7 +59,7 @@ dependencies:
59
59
  type: :development
60
60
  version_requirements: *id003
61
61
  - !ruby/object:Gem::Dependency
62
- name: thor
62
+ name: ruby-debug
63
63
  prerelease: false
64
64
  requirement: &id004 !ruby/object:Gem::Requirement
65
65
  none: false
@@ -69,10 +69,10 @@ dependencies:
69
69
  segments:
70
70
  - 0
71
71
  version: "0"
72
- type: :runtime
72
+ type: :development
73
73
  version_requirements: *id004
74
74
  - !ruby/object:Gem::Dependency
75
- name: builder
75
+ name: thor
76
76
  prerelease: false
77
77
  requirement: &id005 !ruby/object:Gem::Requirement
78
78
  none: false
@@ -84,6 +84,19 @@ dependencies:
84
84
  version: "0"
85
85
  type: :runtime
86
86
  version_requirements: *id005
87
+ - !ruby/object:Gem::Dependency
88
+ name: builder
89
+ prerelease: false
90
+ requirement: &id006 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ type: :runtime
99
+ version_requirements: *id006
87
100
  description: Use Shuck to test basic S3 functionality without actually connecting to S3
88
101
  email:
89
102
  - curtis@sevenforge.com