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

Question: Read the zip as a stream, and upload to Active::Storage #478

Closed
stoivo opened this issue Mar 30, 2021 · 2 comments
Closed

Question: Read the zip as a stream, and upload to Active::Storage #478

stoivo opened this issue Mar 30, 2021 · 2 comments

Comments

@stoivo
Copy link

stoivo commented Mar 30, 2021

I have a zip with files I want to upload to active storage. Some of the files can be several gigabytes so it's important to me that I don't read the whole string into memory. ActiveStorage ueses s3 which needs to know the length ahead. The Zip::InputStream does not expose a size method. I deep my feet into the source and found that Zip::InputStream as a @current_entry which was a size method.

I did a little monkey patching 🙊

class Zip::InputStream
  def size
    return nil unless @current_entry

    @current_entry.size
  end
end

Now my usage has become

Zip::File.open(ENV["BACKUPZIP"]) do |zip_file|
  zip_file.each do |entry|
    blob = ActiveStorage::Blob.find_by(key: entry.name.split("/").last)
    next unless blob

     entry.get_input_stream do |io|
       blob.upload io
     end
  end
end

My question is if this is a patch you want to have into rubyzip?
Do you want me to make a PR?

@stoivo
Copy link
Author

stoivo commented Mar 30, 2021

Closing because it is a duplicate of #451

@hainesr
Copy link
Member

hainesr commented May 13, 2021

Thanks. I have commented on the other issue.

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

No branches or pull requests

2 participants