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.
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  #
3
3
  class GridFS
4
- const_set :Version, '1.1.2'
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
- while((buf = io.read(chunkSize)))
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
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "mongoid-grid_fs"
6
- spec.version = "1.1.2"
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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-grid_fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: