minor: cleanup

This commit is contained in:
Kyle Banker 2009-12-15 16:40:40 -05:00
parent 2c417bb6ab
commit 2fb5c92b60
4 changed files with 41 additions and 30 deletions

View File

@ -264,32 +264,6 @@ module GridFS
end
end
def read_partial(len, buf=nil)
buf ||= ''
byte = self.getc
while byte != nil && (len == nil || len > 0)
buf << byte.chr
len -= 1 if len
byte = self.getc if (len == nil || len > 0)
end
buf
end
def read_all(buf=nil)
buf ||= ''
while true do
if (@curr_chunk.pos > 0)
data = @curr_chunk.data.to_s
buf += data[@position, data.length]
else
buf += @curr_chunk.data.to_s
end
break if @curr_chunk.chunk_number == last_chunk_number
@curr_chunk = nth_chunk(@curr_chunk.chunk_number + 1)
end
buf
end
def readchar
byte = self.getc
raise EOFError.new if byte == nil
@ -489,6 +463,32 @@ module GridFS
h
end
def read_partial(len, buf=nil)
buf ||= ''
byte = self.getc
while byte != nil && (len == nil || len > 0)
buf << byte.chr
len -= 1 if len
byte = self.getc if (len == nil || len > 0)
end
buf
end
def read_all(buf=nil)
buf ||= ''
while true do
if (@curr_chunk.pos > 0)
data = @curr_chunk.data.to_s
buf += data[@position, data.length]
else
buf += @curr_chunk.data.to_s
end
break if @curr_chunk.chunk_number == last_chunk_number
@curr_chunk = nth_chunk(@curr_chunk.chunk_number + 1)
end
buf
end
def delete_chunks
chunk_collection.remove({'files_id' => @files_id}) if @files_id
@curr_chunk = nil

View File

@ -71,6 +71,17 @@ class GridStoreTest < Test::Unit::TestCase
assert_equal "hello", GridStore.read(@@db, 'foobar', 5)
end
def test_read_with_and_without_length
GridStore.open(@@db, 'read-types', 'w') do |f|
f.write('hello, there')
end
GridStore.open(@@db, 'read-types', 'r') do |f|
assert_equal 'hello, ', f.read(7)
assert_equal 'there', f.read
end
end
def test_access_length
assert_equal 13, GridStore.new(@@db, 'foobar').length
end

View File

@ -34,7 +34,7 @@ class TestThreading < Test::Unit::TestCase
end
end
end
100.times do |i|
threads[i].join
end
@ -54,7 +54,7 @@ class TestThreading < Test::Unit::TestCase
end
end
end
100.times do |i|
threads[i].join
end

View File

@ -36,7 +36,7 @@ class TestThreadingLargePool < Test::Unit::TestCase
end
end
end
100.times do |i|
threads[i].join
end
@ -56,7 +56,7 @@ class TestThreadingLargePool < Test::Unit::TestCase
end
end
end
100.times do |i|
threads[i].join
end