duracloud-client 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aea6659762321bf17ab4ebb8e64267be0516cc0f
4
- data.tar.gz: f156ad57e051818a4ceb30a0e1f9ecf43d875f7b
3
+ metadata.gz: 36e3c1de47db33c4726afabdafce50534028f1ab
4
+ data.tar.gz: 45d3130e4f61ff3dc6ef0d2575c6c59f18a882ae
5
5
  SHA512:
6
- metadata.gz: ade9f4d0a1ffafff2b16e368c22a9e00a5bd714e300832ebf42cda0a99ac24c3f36e43fc542fafce5913e316feac47e14b0aaf8017473f0ce8a602073af79ad3
7
- data.tar.gz: 310a399f320345f3c8ea7ba4e3187c97f82c2796f9e3c1b689065d1c36f8b171d4dc29d447393496faaa4010ceb984091d1ed57c417201a7c5a6282e95f8c456
6
+ metadata.gz: 38d9045baee5637769976908f3add414414b59e5b7aa2f5dd3011f0ad00c4fe601bf78fdfc3af90dd1bcdaf54e63434a8d90eeb8333708070894aae2b26267b3
7
+ data.tar.gz: c2efe8e7282a5e75d10b01db0a2561d770deb91043d89990c7820f62508e488e840cdc2819d90a05261571c32be1fa61d43f4b91e55cea4ec83e1dfc1c3bee04
@@ -10,6 +10,8 @@ module Duracloud
10
10
  include Persistence
11
11
  include HasProperties
12
12
 
13
+ CHUNK_SIZE = 1024 * 16
14
+
13
15
  after_save :changes_applied
14
16
 
15
17
  # Does the content exist in DuraCloud?
@@ -64,7 +66,7 @@ module Duracloud
64
66
  # @raise [Duracloud::NotFoundError] the content does not exist in DuraCloud.
65
67
  def load_body
66
68
  response = Client.get_content(*args, **query)
67
- set_body(response) # don't use setter b/c marks as dirty
69
+ @body = response.body # don't use setter b/c marks as dirty
68
70
  persisted!
69
71
  end
70
72
 
@@ -76,7 +78,7 @@ module Duracloud
76
78
  end
77
79
 
78
80
  def body=(str_or_io)
79
- set_body(str_or_io)
81
+ @body = str_or_io
80
82
  body_will_change!
81
83
  end
82
84
 
@@ -104,8 +106,8 @@ module Duracloud
104
106
 
105
107
  private
106
108
 
107
- def set_body(str_or_io)
108
- @body = StringIO.new(read_string_or_io(str_or_io), "r")
109
+ def io_like?
110
+ body.respond_to?(:read) && body.respond_to?(:rewind)
109
111
  end
110
112
 
111
113
  def set_properties
@@ -126,10 +128,17 @@ module Duracloud
126
128
  end
127
129
 
128
130
  def md5
129
- body.rewind
130
- Digest::MD5.hexdigest(body.read)
131
- ensure
132
- body.rewind
131
+ digest = Digest::MD5.new
132
+ if io_like?
133
+ body.rewind
134
+ while chunk = body.read(CHUNK_SIZE) do
135
+ digest << chunk
136
+ end
137
+ body.rewind
138
+ else
139
+ digest << body
140
+ end
141
+ digest.hexdigest
133
142
  end
134
143
 
135
144
  def properties_class
@@ -154,25 +163,6 @@ module Duracloud
154
163
  end
155
164
  end
156
165
 
157
- def read_string_or_io(str_or_io)
158
- if str_or_io.respond_to?(:read)
159
- read_io_like(str_or_io)
160
- elsif str_or_io.respond_to?(:to_str)
161
- str_or_io.to_str
162
- else
163
- raise ArgumentError, "IO-like or String-like argument required."
164
- end
165
- end
166
-
167
- def read_io_like(io_like)
168
- begin
169
- io_like.rewind if io_like.respond_to?(:rewind)
170
- io_like.read
171
- ensure
172
- io_like.rewind if io_like.respond_to?(:rewind)
173
- end
174
- end
175
-
176
166
  def args
177
167
  [ space_id, content_id ]
178
168
  end
@@ -1,3 +1,3 @@
1
1
  module Duracloud
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1 @@
1
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in placerat sapien, quis vestibulum lectus. Cras ut vestibulum dolor. Nunc nunc urna, laoreet vitae lacinia at, cursus non lectus. Sed non orci feugiat, ullamcorper lacus non, gravida felis. Duis posuere dictum mi, id vehicula turpis ullamcorper eu. Nam egestas quam vel ultrices pharetra. Maecenas sollicitudin fermentum massa eu tincidunt. Nunc mollis metus in lorem aliquam, quis mattis leo condimentum.
@@ -1,7 +1,7 @@
1
1
  module Duracloud
2
2
  RSpec.describe AuditLog do
3
3
 
4
- let(:tsv) { File.read(File.join(File.expand_path('../../fixtures/audit_log.tsv', __FILE__))) }
4
+ let(:tsv) { File.read(File.expand_path('../../fixtures/audit_log.tsv', __FILE__)) }
5
5
 
6
6
  before {
7
7
  allow(subject).to receive(:tsv) { tsv }
@@ -1,7 +1,7 @@
1
1
  module Duracloud
2
2
  RSpec.describe BitIntegrityReport do
3
3
 
4
- let(:tsv) { File.read(File.join(File.expand_path('../../fixtures/bit_integrity_report.tsv', __FILE__))) }
4
+ let(:tsv) { File.read(File.expand_path('../../fixtures/bit_integrity_report.tsv', __FILE__)) }
5
5
 
6
6
  before {
7
7
  allow(subject).to receive(:tsv) { tsv }
@@ -88,6 +88,18 @@ module Duracloud
88
88
  end
89
89
  end
90
90
  end
91
+ describe "when the body is a file" do
92
+ let(:path) { File.expand_path('../../fixtures/lorem_ipsum.txt', __FILE__) }
93
+ let(:file) { File.new(path, "rb") }
94
+ before {
95
+ stub_request(:put, url).with(body: File.read(path))
96
+ .to_return(status: 201)
97
+ }
98
+ it "stores the file content" do
99
+ subject.body = file
100
+ subject.save
101
+ end
102
+ end
91
103
  end
92
104
 
93
105
  describe "#delete" do
@@ -1,7 +1,7 @@
1
1
  module Duracloud
2
2
  RSpec.describe Manifest do
3
3
 
4
- let(:tsv) { File.read(File.join(File.expand_path('../../fixtures/manifest.tsv', __FILE__))) }
4
+ let(:tsv) { File.read(File.expand_path('../../fixtures/manifest.tsv', __FILE__)) }
5
5
 
6
6
  before {
7
7
  allow(subject).to receive(:tsv) { tsv }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duracloud-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -180,6 +180,7 @@ files:
180
180
  - lib/duracloud/version.rb
181
181
  - spec/fixtures/audit_log.tsv
182
182
  - spec/fixtures/bit_integrity_report.tsv
183
+ - spec/fixtures/lorem_ipsum.txt
183
184
  - spec/fixtures/manifest.tsv
184
185
  - spec/spec_helper.rb
185
186
  - spec/unit/audit_log_spec.rb
@@ -218,6 +219,7 @@ summary: Ruby client for communicating with DuraCloud
218
219
  test_files:
219
220
  - spec/fixtures/audit_log.tsv
220
221
  - spec/fixtures/bit_integrity_report.tsv
222
+ - spec/fixtures/lorem_ipsum.txt
221
223
  - spec/fixtures/manifest.tsv
222
224
  - spec/spec_helper.rb
223
225
  - spec/unit/audit_log_spec.rb