Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputStream doesn't implement length method #276

Open
zacstewart opened this issue Feb 25, 2016 · 3 comments
Open

InputStream doesn't implement length method #276

zacstewart opened this issue Feb 25, 2016 · 3 comments
Labels

Comments

@zacstewart
Copy link
Contributor

I'm trying out upload files from a zip archive without splitting them apart on disk. I thought I'd be able to pass the InputStream directly into UploadIO.new and everything would be fine.

However, it looks like in order to multi-part the message body, it needs to know the length of the IO object. I'm happy to try adding this method, but is it even possible to know without reading the entire stream (and then rewinding it)?

@hainesr
Copy link
Member

hainesr commented Jun 6, 2021

InputStream now has a size method for this sort of thing (#478). Is length effectively an alias for this? Zip bombs are a concern, but my reason for allowing this is that the receiver should be able to use the stated size to not accept any more data than that.

@zacstewart
Copy link
Contributor Author

It's been so long since I opened this issue I don't recall all the details, but the gist was I wanted to wrap it in an UploadIO.new, which I think can take a File handler or any other IO that implements a few methods, and length was one of the methods it wanted.

@hainesr
Copy link
Member

hainesr commented Jun 7, 2021

Yeah, sorry, I'm catching up on some old issues 😄

Having looked at UploadIO I think it's only really designed for Files or file-backed IOs. File itself doesn't implement length, and this comment on UploadIO suggests that if you do supply an IO you need to also supply the file that contains the data as well - which you could only do for an entry from a zip file if you wrote it out to disk anyway. I think you could make it work with a StringIO - which is the one IO that does implement length and doesn't need a filename for UploadIO.

It seems complicated though. Not sure why the UploadIO folks don't use size as then you really could use any IO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants