Issue #9 resolved

There seems to be no way to delete/remove files from an archive

silasdavis
created an issue

... Or else I'm just failing to find it by inspecting the methods or reading the docs.

I was hoping for something like:

      Zip::Archive.open('archive.zip) do |a|
        a.remove('file.txt')
        a.remove('a_directory')
      end

Does it really not provide this functionality? Seems to do everything else.

Comments (2)

  1. silasdavis reporter

    Yes there is, will add to wiki when I get a chance, also was ignorant of how ZIP files only store files and their paths as entries. I was expecting zipruby to have populated a hash table of entries on open, but it doesn't, which on reflection is a good thing in case you only want to scan once and not have the overhead.

    Here's an example of deleting a directory:

          Zip::Archive.open(tmp_file_path) do |ar|
            delete_pattern = dir_pattern('META-INF')
            n = ar.num_files # number of entries
            n.times do |i|
              entry_name = ar.get_name(i) # get entry name from archive
              ar.fdelete(i) if delete_pattern === entry_name
            end
          end
    
  2. Log in to comment