Skip to content

Allow chunked uploads to work with IO streams other than files #110

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jcmfernandes
Copy link
Contributor

@jcmfernandes jcmfernandes commented Sep 9, 2021

I bumped into https://discuss.rubyonrails.org/t/transferring-files-from-s3-to-box-in-chunks-without-a-tmp-file/78841 as it landed on my inbox - major coincidence 😅 - and just like reported in #106, chunked uploads aren't currently working for IO streams other than files. This PR fixes that, and I took the chance to do some small refactoring, extracting some methods out of #chunked_upload_to_session_from_io.

add_development_dependency states that dependencies are necessary when
developing an app using this gem, as in, these gems are added to the
development group. We don't need that.
This was failing on my side. Was test implicitly defined in previoous
RSpec versions?
@@ -9,11 +9,13 @@ def chunked_upload_create_session_new_file(path_to_file, parent, name: nil)
end
end

def chunked_upload_create_session_new_file_from_io(io, parent, name)
def chunked_upload_create_session_new_file_from_io(io, parent, name, io_size: nil)
io_size ||= io.size
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to keep in mind is that #size is not part of IO's public interface.

@xhocquet
Copy link
Collaborator

xhocquet commented Sep 9, 2021

Hey @jcmfernandes , thanks for the contribution! I'll definitely be taking a look since this seems like a great quality of life improvement.

At first glance, the things that concern me the most are the Gemfile changes and added dependency. When developing gems, smart people tell us to stick to mostly-empty Gemfiles and instead stick to the gemspec to keep everything in one place.

As for the stringio addition, I don't know enough about what it's doing to know whether it's absolutely necessary or not. The goal of course is to have as few dependencies as possible and to keep this gem nice and small!

@jcmfernandes
Copy link
Contributor Author

Hey @xhocquet thanks for the quick reply!

Regarding the Gemfile/gemspec stuff, I should probably write a blog post on this 😄 it's my understanding that the blog post you referenced is somewhat outdated. With that said, one thing is very much up to date: do not check-in Gemfile.lock when developing a gem.

When you add spec.add_development_dependency "xpto" to a gemspec, that's the equivalent of adding gem xpto to group :development in the Gemfile of the application/other gem that is including your gem as a dependency. This sentence is a bit confusing but I can't find another way of making it clearer. So, add_development_dependency has nothing to do with the development of your gem, but with the development of other apps/gems that include your gem. A good example is codecov. We use codecov here to assess this code's coverage. It's a development tool in the context of this gem. We don't need to "force" others depending on our gem to also have codecov as one of their dependencies, not even as a development dependency.

Furthermore, sometimes it's relevant to have the same gem referenced in the gemspec and Gemfile. That usually happens when you want to change the source of the gem; say you want to install your fork of codecov that lives in your github account. In that case, you would add spec.add_development_dependency "codecov" to the gemspec and gem "codecov", git: "https://github.com/..." to your Gemfile below the call to gemspec.

Long, possibly confusing, sorry about that.

Regarding stringio, it's part of ruby's standard library. It's necessary as we need to create IO streams that are backed by strings, and that's exactly what stringio is for.

@xhocquet
Copy link
Collaborator

xhocquet commented Sep 9, 2021

@jcmfernandes Thanks for the context, definitely some stuff to chew on and it's definitely possible that the top google result is outdated! It was my understanding that using gemspec would not force apps using this gem to require the development gems when installing, so I'll need to go reread the docs to clarify my understanding. The goal of course is that clients don't download any dependencies besides the 4 minumum today (5 if you want parallel chunked uploads)

Regarding stringio, I think I just mixed it up with the dependencies, my mistake!

Doing so can actually backfire. PaaS like heroku run bundle install with
`--without development:test`, effectively excluding gems in groups
development and test. So having gem parallel declared as development
dependency would cause `require "parallel"` locally but then fail once
pushed to the PaaS.
@jcmfernandes
Copy link
Contributor Author

No worries! Being 100% honest, I actually don't use this gem as of today. I had to create a new box developer account to run the test suite 😅 but I bumped into that post in Rails' discuss and well, I had to scratch the itch.

Still on the #add_development_dependency topic, in 98903aa I detail why I'm doing the change. I hope it makes sense.

Reiterating that it doesn't make sense to cut a new release without first merging #106.

@moenodedev
Copy link

Do you need any help testing this change?

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

Successfully merging this pull request may close these issues.

3 participants