Замена файла в zip-архиве - PullRequest
0 голосов
/ 12 марта 2012

При использовании Ruby (1.9.3) мне нужно заменить один файл в zip-архиве.

Ситуация следующая.У меня есть ~ 1000 zip-архивов, которые необходимо обновить, в частности один файл в каждом из них необходимо заменить.Все архивы имеют одинаковую структуру.Есть ли быстрый и грязный способ для Ruby или библиотеки / гема для Ruby просто сказать «замените файл в этом zip-архиве этим файлом в файловой системе»?моего собственного тем временем.

Ответы [ 2 ]

1 голос
/ 12 марта 2012

Вы можете использовать команду zip, вызванную из ruby, которая, вероятно, будет лучшим решением.С zip manpage zip manpage

       -d
   --delete
          Remove (delete) entries from a zip archive.  For example:

                 zip -d foo foo/tom/junk foo/harry/\* \*.o

          will remove the entry foo/tom/junk, all of the files that start with foo/harry/, and all of the files that end with .o (in any path).  Note that  shell  path‐
          name expansion has been inhibited with backslashes, so that zip can see the asterisks, enabling zip to match on the contents of the zip archive instead of the
          contents of the current directory.  (The backslashes are not used on MSDOS-based platforms.)  Can also use quotes to escape the asterisks as in

                 zip -d foo foo/tom/junk "foo/harry/*" "*.o"

          Not escaping the asterisks on a system where the shell expands wildcards could result in the asterisks being converted to a  list  of  files  in  the  current
          directory and that list used to delete entries from the archive.

          Under  MSDOS,  -d  is  case sensitive when it matches names in the zip archive.  This requires that file names be entered in upper case if they were zipped by
          PKZIP on an MSDOS system.  (We considered making this case insensitive on systems where paths were case insensitive, but it is possible the archive came  from
          a  system  where case does matter and the archive could include both Bar and bar as separate files in the archive.)  But see the new option -ic to ignore case
          in the archive.

Если вы хотите получить решение с чистым рубином, посмотрите ZipFileSystem

0 голосов
/ 12 марта 2012

Zip :: ZipFile выглядит многообещающе.По-видимому, есть способ удалять и добавлять файлы в zip-архив.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...