active_fedora_streamable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+ # see active_fedora_streamable.gemspec
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Columbia University Libraries, New York, NY
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,17 @@
1
+ An ActiveFedora mixin that allows a datastream dissemination response to be streamed back in blocks without reading all content into memory.
2
+
3
+ Include the mixin in your ActiveFedora::Datastream subclass:
4
+
5
+ bc. class BigData < ActiveFedora::Datastream
6
+ include ActiveFedora::Datastreams::Streamable
7
+ end
8
+
9
+ bc. class DataContainer < ActiveFedora::Base
10
+ has_file_datastream :name=>'bigData', :type=> BigData
11
+ end
12
+
13
+ and then set the response_body in your controller:
14
+
15
+ bc. DataContainer.find('demo:1').bigData.stream(self)
16
+
17
+ The iterator returned from #stream will write the bytes of a datastream dissemination back to the client in segments, without reading all of the content into memory first. It will not assign the output of the datastream dissemination to the ActiveFedora::Datastream's content attribute.
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "active_fedora_streamable"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "active_fedora_streamable"
7
+ s.version = ActiveFedora::Datastreams::Streamable::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Benjamin Armintor"]
10
+ s.email = ["armintor@gmail.com"]
11
+ s.homepage = %q{https://github.com/cul/active_fedora_streamable}
12
+ s.summary = %q{An ActiveFedora mixin that allows a datastream dissemination response to be streamed back}
13
+ s.description = %q{An ActiveFedora mixin that allows a datastream dissemination response to be streamed back in blocks without reading all content into memory.}
14
+
15
+ s.rubygems_version = %q{1.3.7}
16
+
17
+ s.add_dependency('active-fedora', '>=4.2.0')
18
+ s.add_dependency("activesupport", '~>3.2.0')
19
+ s.add_dependency("rubydora", '~>0.5.9')
20
+ s.add_development_dependency("yard")
21
+ s.add_development_dependency("RedCloth") # for RDoc formatting
22
+ s.add_development_dependency("rake")
23
+ s.add_development_dependency("rspec", ">= 2.9.0")
24
+ s.add_development_dependency("mocha", "0.10.5")
25
+
26
+ s.files = `git ls-files`.split("\n")
27
+ s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
28
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
29
+ s.extra_rdoc_files = [
30
+ "LICENSE.txt",
31
+ "README.textile"
32
+ ]
33
+ s.require_paths = ["lib"]
34
+
35
+ end
@@ -0,0 +1,29 @@
1
+ require 'active-fedora'
2
+ module ActiveFedora::Datastreams
3
+ module Streamable
4
+ VERSION = '0.1.0'
5
+ # the output of this method should be assigned to the response_body of a controller
6
+ # the bytes returned from the datastream dissemination will be written to the response
7
+ # piecemeal rather than being loaded into memory as a String
8
+ def stream(controller, parms=Hash.new)
9
+ parms = {:dsid=>self.dsid, :pid=>self.pid, :finished=>false}.merge parms
10
+ controller.headers['Last-Modified'] = self.lastModifiedDate || Time.now.ctime.to_s
11
+ if self.dsSize
12
+ controller.headers['Content-Length'] = self.dsSize.to_s
13
+ else
14
+ controller.headers['Transfer-Encoding'] = 'chunked'
15
+ end
16
+ #controller.response_body = ActiveFedora::Datastreams::Streamable::Streamer.new parms
17
+ controller.response_body = Enumerator.new do |blk|
18
+ repo = ActiveFedora::Base.connection_for_pid(parms[:pid])
19
+ repo.datastream_dissemination(parms) do |res|
20
+ res.read_body do |seg|
21
+ blk << seg
22
+ end
23
+ # this is a hack for https://github.com/archiloque/rest-client/issues/134
24
+ repo.client.options.delete :block_response
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_fedora_streamable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Benjamin Armintor
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-07-19 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: active-fedora
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 55
29
+ segments:
30
+ - 4
31
+ - 2
32
+ - 0
33
+ version: 4.2.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: activesupport
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 15
45
+ segments:
46
+ - 3
47
+ - 2
48
+ - 0
49
+ version: 3.2.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rubydora
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 25
61
+ segments:
62
+ - 0
63
+ - 5
64
+ - 9
65
+ version: 0.5.9
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: yard
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: RedCloth
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ type: :development
95
+ version_requirements: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ name: rake
98
+ prerelease: false
99
+ requirement: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ type: :development
109
+ version_requirements: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec
112
+ prerelease: false
113
+ requirement: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 43
119
+ segments:
120
+ - 2
121
+ - 9
122
+ - 0
123
+ version: 2.9.0
124
+ type: :development
125
+ version_requirements: *id007
126
+ - !ruby/object:Gem::Dependency
127
+ name: mocha
128
+ prerelease: false
129
+ requirement: &id008 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - "="
133
+ - !ruby/object:Gem::Version
134
+ hash: 61
135
+ segments:
136
+ - 0
137
+ - 10
138
+ - 5
139
+ version: 0.10.5
140
+ type: :development
141
+ version_requirements: *id008
142
+ description: An ActiveFedora mixin that allows a datastream dissemination response to be streamed back in blocks without reading all content into memory.
143
+ email:
144
+ - armintor@gmail.com
145
+ executables: []
146
+
147
+ extensions: []
148
+
149
+ extra_rdoc_files:
150
+ - LICENSE.txt
151
+ - README.textile
152
+ files:
153
+ - Gemfile
154
+ - LICENSE.txt
155
+ - README.textile
156
+ - active_fedora_streamable.gemspec
157
+ - lib/active_fedora_streamable.rb
158
+ homepage: https://github.com/cul/active_fedora_streamable
159
+ licenses: []
160
+
161
+ post_install_message:
162
+ rdoc_options: []
163
+
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ hash: 3
172
+ segments:
173
+ - 0
174
+ version: "0"
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ hash: 3
181
+ segments:
182
+ - 0
183
+ version: "0"
184
+ requirements: []
185
+
186
+ rubyforge_project:
187
+ rubygems_version: 1.8.24
188
+ signing_key:
189
+ specification_version: 3
190
+ summary: An ActiveFedora mixin that allows a datastream dissemination response to be streamed back
191
+ test_files: []
192
+
193
+ has_rdoc: