lib/mongo/grid/stream/write.rb in mongo-2.12.4 vs lib/mongo/grid/stream/write.rb in mongo-2.13.0.beta1
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (C) 2014-2019 MongoDB, Inc.
+# Copyright (C) 2014-2020 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -80,29 +80,23 @@
@options.freeze
@filename = @options[:filename]
@open = true
end
- # Write to the GridFS bucket from the source stream or a string.
+ # Write to the GridFS bucket from the source stream.
#
# @example Write to GridFS.
# stream.write(io)
#
- # @param [ String | IO ] io The string or IO object to upload from.
+ # @param [ IO ] io The source io stream to upload from.
#
# @return [ Stream::Write ] self The write stream itself.
#
# @since 2.1.0
def write(io)
ensure_open!
@indexes ||= ensure_indexes!
- @length += if io.respond_to?(:bytesize)
- # String objects
- io.bytesize
- else
- # IO objects
- io.size
- end
+ @length += io.size
chunks = File::Chunk.split(io, file_info, @n)
@n += chunks.size
chunks_collection.insert_many(chunks) unless chunks.empty?
self
end