Skip to content

Recognize #size on an IO, not just #length? #110

@jrochkind

Description

@jrochkind

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.

i have also filed an issue on Down asking if they would consider implemetning #length. Ruby's lack of clear established standard contract/apI for non-File IO leaves us guessing how to make things compatible! But in this case, it looks to me like multipart-post will work fine with Down::ChunkedIO if only this simple issue were resolved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions