@@ -177,7 +177,7 @@ def initialize(database, options = {})
177177 #
178178 # @since 2.0.0
179179 def prefix
180- @options [ :fs_name ] || @options [ :bucket_name ] || DEFAULT_ROOT
180+ @options [ :fs_name ] || @options [ :bucket_name ] || DEFAULT_ROOT
181181 end
182182
183183 # Remove a single file from the GridFS.
@@ -230,7 +230,8 @@ def delete(id)
230230 #
231231 # @since 2.1.0
232232 def open_download_stream ( id , options = nil )
233- read_stream ( id , options ) . tap do |stream |
233+ options = Hash [ ( options || { } ) . map { |k , v | [ k . to_sym , v ] } ]
234+ read_stream ( id , **options ) . tap do |stream |
234235 if block_given?
235236 begin
236237 yield stream
@@ -348,15 +349,15 @@ def download_to_stream_by_name(filename, io, opts = {})
348349 download_to_stream ( open_download_stream_by_name ( filename , opts ) . file_id , io )
349350 end
350351
351- # Opens an upload stream to GridFS to which the contents of a user file came be written.
352+ # Opens an upload stream to GridFS to which the contents of a file or
353+ # blob can be written.
352354 #
353- # @example Open a stream to which the contents of a file came be written.
354- # fs.open_upload_stream('a-file.txt')
355- #
356- # @param [ String ] filename The filename of the file to upload.
355+ # @param [ String ] filename The name of the file in GridFS.
357356 # @param [ Hash ] opts The options for the write stream.
358357 #
359- # @option opts [ Object ] :file_id An optional unique file id. An ObjectId is generated otherwise.
358+ # @option opts [ Object ] :file_id An optional unique file id.
359+ # A BSON::ObjectId is automatically generated if a file id is not
360+ # provided.
360361 # @option opts [ Integer ] :chunk_size Override the default chunk size.
361362 # @option opts [ Hash ] :metadata User data for the 'metadata' field of the files
362363 # collection document.
@@ -375,7 +376,8 @@ def download_to_stream_by_name(filename, io, opts = {})
375376 #
376377 # @since 2.1.0
377378 def open_upload_stream ( filename , opts = { } )
378- write_stream ( filename , opts ) . tap do |stream |
379+ opts = Hash [ opts . map { |k , v | [ k . to_sym , v ] } ]
380+ write_stream ( filename , **opts ) . tap do |stream |
379381 if block_given?
380382 begin
381383 yield stream
@@ -462,12 +464,12 @@ def write_concern
462464 #
463465 # @option opts [ BSON::Document ] :file_info_doc For internal
464466 # driver use only. A BSON document to use as file information.
465- def read_stream ( id , opts = nil )
466- Stream . get ( self , Stream ::READ_MODE , { file_id : id } . update ( options ) . update ( opts || { } ) )
467+ def read_stream ( id , ** opts )
468+ Stream . get ( self , Stream ::READ_MODE , { file_id : id } . update ( options ) . update ( opts ) )
467469 end
468470
469- def write_stream ( filename , opts )
470- Stream . get ( self , Stream ::WRITE_MODE , { filename : filename } . merge! ( options ) . merge! ( opts ) )
471+ def write_stream ( filename , ** opts )
472+ Stream . get ( self , Stream ::WRITE_MODE , { filename : filename } . update ( options ) . update ( opts ) )
471473 end
472474
473475 def chunks_name
0 commit comments