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

How to write a zip file without loading the whole source files or the zip file into memory? #261

Open
georgeu2000 opened this issue Nov 29, 2015 · 3 comments

Comments

@georgeu2000
Copy link

zipfile.add(filename, folder + '/' + filename) seems to be using a large amount of memory.

What is a good way to add a file to a zip file using a minimum of memory?

@mnaberez
Copy link
Contributor

This was reported in #233 and should be fixed by #250.

@georgeu2000
Copy link
Author

OK, thanks for the info.

I was able to make it work this way. I guess it won't handle encryption...

  Zip::File.open( zipfile_name, Zip::File::CREATE ) do | zipfile |
    files.each.with_index(1) do | filename, i |
      append_file zipfile, filename, "#{ local_path }/#{ filename }"
    end
  end

  BUFFER_SIZE = 1000000
  def append_file zipfile, filename, path_and_file
    zipfile.get_output_stream( filename ) do | os | 
      open( path_and_file ) do | f |
        while buffer = f.read( BUFFER_SIZE )
          os.write buffer
        end
      end
    end
  end

@sandstrom
Copy link

I'm doing some issue gardening 🌱🌿 🌷 and came upon this issue. Since it's quite old I just wanted to ask if this is still relevant? If it isn't, maybe we can close this issue?

By closing some old issues we reduce the list of open issues to a more manageable set.

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

3 participants