mongoid-grid_fs 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongoid-grid_fs.rb +23 -2
- data/mongoid-grid_fs.gemspec +1 -1
- metadata +1 -1
data/lib/mongoid-grid_fs.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
##
|
2
2
|
#
|
3
3
|
class GridFS
|
4
|
-
const_set :Version, '1.
|
4
|
+
const_set :Version, '1.2.0'
|
5
5
|
|
6
6
|
class << GridFS
|
7
7
|
def version
|
@@ -185,7 +185,7 @@
|
|
185
185
|
attributes[:contentType] ||=
|
186
186
|
GridFS.extract_content_type(filename) || file.contentType
|
187
187
|
|
188
|
-
|
188
|
+
GridFS.chunking(io, chunkSize) do |buf|
|
189
189
|
md5 << buf
|
190
190
|
length += buf.size
|
191
191
|
chunk = file.chunks.build
|
@@ -422,6 +422,27 @@
|
|
422
422
|
end
|
423
423
|
end
|
424
424
|
|
425
|
+
def GridFS.chunking(io, chunk_size, &block)
|
426
|
+
if io.method(:read).arity == 0
|
427
|
+
data = io.read
|
428
|
+
i = 0
|
429
|
+
loop do
|
430
|
+
offset = i * chunk_size
|
431
|
+
length = i + chunk_size < data.size ? chunk_size : data.size - offset
|
432
|
+
|
433
|
+
break if offset >= data.size
|
434
|
+
|
435
|
+
buf = data[offset, length]
|
436
|
+
block.call(buf)
|
437
|
+
i += 1
|
438
|
+
end
|
439
|
+
else
|
440
|
+
while((buf = io.read(chunk_size)))
|
441
|
+
block.call(buf)
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
425
446
|
def GridFS.rewind(io, &block)
|
426
447
|
begin
|
427
448
|
pos = io.pos
|
data/mongoid-grid_fs.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "mongoid-grid_fs"
|
6
|
-
spec.version = "1.
|
6
|
+
spec.version = "1.2.0"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "mongoid-grid_fs"
|
9
9
|
spec.description = "a mongoid 3/moped compatible implementation of the grid_fs specification"
|