You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ruby's lack of clear standard interface for IO bytes again.
I am trying to use with a non-File IO, specifically a [Down](https://github.com/janko/down)::ChunkedIO.
It has a #size method to return bytesize, but not a #length method.
Here in this gem, we look for #length but not #size, and if not found assume it's something (not sure what this was targetting) with a local_path method and try to use File.size to look up it's path.
But a Down::ChunkedIO does not have a local_path either, so of course we raise.
StringIO, which was perhaps being targetted, has a #length as well as a #size. (I think they are synonyms, although not entirely sure if length can depend on encoding?)
Any chance of checking for size in addition to length here, which will, I have tested, make it work with a DownIO::Chunked obj too.
Activity
ioquatix commentedon Jun 14, 2025
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)Looks pretty janky to me. IOW, I'm open to something better.
bquorning commentedon May 11, 2026
I’ll just mention that Rails’
ActionDispatch::Http::UploadedFilehas the exact same behavior (see https://github.com/rails/rails/blob/v8.1.3/actionpack/lib/action_dispatch/http/upload.rb#L92-L95)