in which some lame-ass libraries read(with_no_size)
This commit is contained in:
parent
8c4184e436
commit
0252373954
@ -1,7 +1,7 @@
|
|||||||
##
|
##
|
||||||
#
|
#
|
||||||
class GridFS
|
class GridFS
|
||||||
const_set :Version, '1.1.2'
|
const_set :Version, '1.2.0'
|
||||||
|
|
||||||
class << GridFS
|
class << GridFS
|
||||||
def version
|
def version
|
||||||
@ -185,7 +185,7 @@
|
|||||||
attributes[:contentType] ||=
|
attributes[:contentType] ||=
|
||||||
GridFS.extract_content_type(filename) || file.contentType
|
GridFS.extract_content_type(filename) || file.contentType
|
||||||
|
|
||||||
while((buf = io.read(chunkSize)))
|
GridFS.chunking(io, chunkSize) do |buf|
|
||||||
md5 << buf
|
md5 << buf
|
||||||
length += buf.size
|
length += buf.size
|
||||||
chunk = file.chunks.build
|
chunk = file.chunks.build
|
||||||
@ -422,6 +422,27 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def GridFS.chunking(io, chunk_size, &block)
|
||||||
|
if io.method(:read).arity == 0
|
||||||
|
data = io.read
|
||||||
|
i = 0
|
||||||
|
loop do
|
||||||
|
offset = i * chunk_size
|
||||||
|
length = i + chunk_size < data.size ? chunk_size : data.size - offset
|
||||||
|
|
||||||
|
break if offset >= data.size
|
||||||
|
|
||||||
|
buf = data[offset, length]
|
||||||
|
block.call(buf)
|
||||||
|
i += 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
while((buf = io.read(chunk_size)))
|
||||||
|
block.call(buf)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def GridFS.rewind(io, &block)
|
def GridFS.rewind(io, &block)
|
||||||
begin
|
begin
|
||||||
pos = io.pos
|
pos = io.pos
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
Gem::Specification::new do |spec|
|
Gem::Specification::new do |spec|
|
||||||
spec.name = "mongoid-grid_fs"
|
spec.name = "mongoid-grid_fs"
|
||||||
spec.version = "1.1.2"
|
spec.version = "1.2.0"
|
||||||
spec.platform = Gem::Platform::RUBY
|
spec.platform = Gem::Platform::RUBY
|
||||||
spec.summary = "mongoid-grid_fs"
|
spec.summary = "mongoid-grid_fs"
|
||||||
spec.description = "a mongoid 3/moped compatible implementation of the grid_fs specification"
|
spec.description = "a mongoid 3/moped compatible implementation of the grid_fs specification"
|
||||||
|
Loading…
Reference in New Issue
Block a user