@@ -13,6 +13,7 @@ def read_and_write_stream(filename, read_length, opts={})
13
13
read_data = ""
14
14
while ( chunk = file . read ( read_length ) )
15
15
read_data << chunk
16
+ break if chunk . empty?
16
17
end
17
18
assert_equal data . length , read_data . length
18
19
end
@@ -195,6 +196,39 @@ class GridTest < Test::Unit::TestCase
195
196
end
196
197
end
197
198
199
+ context "Grid streaming an empty file: " do
200
+ setup do
201
+ @grid = Grid . new ( @db , 'test-fs' )
202
+ filename = 'empty_data'
203
+ @io = File . open ( File . join ( File . dirname ( __FILE__ ) , 'data' , filename ) , 'r' )
204
+ id = @grid . put ( @io , :filename => filename )
205
+ @file = @grid . get ( id )
206
+ @io . rewind
207
+ @data = @io . read
208
+ if @data . respond_to? ( :force_encoding )
209
+ @data . force_encoding ( "binary" )
210
+ end
211
+ end
212
+
213
+ should "be equal in length" do
214
+ @io . rewind
215
+ assert_equal @io . read . length , @file . read . length
216
+ end
217
+
218
+ should "read the file" do
219
+ read_data = ""
220
+ @file . each do |chunk |
221
+ read_data << chunk
222
+ end
223
+ assert_equal @data . length , read_data . length
224
+ end
225
+
226
+ should "read the file if no block is given" do
227
+ read_data = @file . each
228
+ assert_equal @data . length , read_data . length
229
+ end
230
+ end
231
+
198
232
context "Streaming: " do || { }
199
233
setup do
200
234
@grid = Grid . new ( @db , 'test-fs' )
@@ -204,6 +238,10 @@ class GridTest < Test::Unit::TestCase
204
238
read_and_write_stream ( 'small_data.txt' , 1 , :chunk_size => 2 )
205
239
end
206
240
241
+ should "put and get an empty io object" do
242
+ read_and_write_stream ( 'empty_data' , 1 )
243
+ end
244
+
207
245
should "put and get a small io object" do
208
246
read_and_write_stream ( 'small_data.txt' , 1 )
209
247
end
0 commit comments