{"id":22006089,"url":"https://github.com/rubyzip/rubyzip","last_synced_at":"2026-10-19T13:05:27.340Z","repository":{"id":1085929,"uuid":"935822","full_name":"rubyzip/rubyzip","owner":"rubyzip","description":"Official Rubyzip repository","archived":false,"fork":false,"pushed_at":"2026-10-03T07:35:08.000Z","size":3000,"stargazers_count":1432,"open_issues_count":23,"forks_count":334,"subscribers_count":34,"default_branch":"main","last_synced_at":"2026-10-17T15:11:57.065Z","etag":null,"topics":["aes-encryption","encryption","ruby","rubyzip","zip","zip-archive","zip-file"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/rubyzip","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubyzip.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","claude":"CLAUDE.md","gemini":null,"cursor":null,"copilot":null,"dco":null,"cla":null,"disclosure":null}},"created_at":"2010-09-24T10:50:15.000Z","updated_at":"2026-10-14T08:34:19.000Z","dependencies_parsed_at":"2026-09-26T06:29:28.647Z","dependency_job_id":null,"html_url":"https://github.com/rubyzip/rubyzip","commit_stats":{"total_commits":1277,"total_committers":133,"mean_commits":9.601503759398497,"dds":0.6985121378230227,"last_synced_commit":"5b0d25e416814beb062c707c1319eb79b9d4272f"},"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"purl":"pkg:github/rubyzip/rubyzip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyzip%2Frubyzip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyzip%2Frubyzip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyzip%2Frubyzip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyzip%2Frubyzip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubyzip","download_url":"https://codeload.github.com/rubyzip/rubyzip/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyzip%2Frubyzip/sbom","scorecard":{"id":789059,"data":{"date":"2025-08-11","repo":{"name":"github.com/rubyzip/rubyzip","commit":"932ea90f700610207f567cbeba3ac1f323fb22f6"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.9,"checks":[{"name":"Maintained","score":10,"reason":"8 commit(s) and 11 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Code-Review","score":1,"reason":"Found 4/30 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/lint.yml:1","Warn: no topLevel permission defined: .github/workflows/tests.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: BSD 2-Clause \"Simplified\" License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/rubyzip/rubyzip/lint.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/lint.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/rubyzip/rubyzip/lint.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/rubyzip/rubyzip/tests.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/rubyzip/rubyzip/tests.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/rubyzip/rubyzip/tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/rubyzip/rubyzip/tests.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/rubyzip/rubyzip/tests.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:75: update your workflow using https://app.stepsecurity.io/secureworkflow/rubyzip/rubyzip/tests.yml/master?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   5 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-23T06:56:35.652Z","repository_id":1085929,"created_at":"2025-08-23T06:56:35.652Z","updated_at":"2025-08-23T06:56:35.652Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":344872684,"owners_count":38334703,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-10-03T21:59:58.778Z","status":"online","status_checked_at":"2026-10-17T02:00:06.547Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes-encryption","encryption","ruby","rubyzip","zip","zip-archive","zip-file"],"created_at":"2024-11-30T01:08:54.975Z","updated_at":"2026-10-19T13:05:27.334Z","avatar_url":"https://github.com/rubyzip.png","language":"Ruby","funding_links":[],"categories":["Ruby","Gems","Compression"],"sub_categories":["Misc"],"readme":"# rubyzip\n\n[![Gem Version](https://badge.fury.io/rb/rubyzip.svg)](http://badge.fury.io/rb/rubyzip)\n[![Tests](https://github.com/rubyzip/rubyzip/actions/workflows/tests.yml/badge.svg)](https://github.com/rubyzip/rubyzip/actions/workflows/tests.yml)\n[![Linter](https://github.com/rubyzip/rubyzip/actions/workflows/lint.yml/badge.svg)](https://github.com/rubyzip/rubyzip/actions/workflows/lint.yml)\n[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)\n[![Maintainability](https://qlty.sh/gh/rubyzip/projects/rubyzip/maintainability.svg)](https://qlty.sh/gh/rubyzip/projects/rubyzip)\n[![Coverage Status](https://img.shields.io/coveralls/rubyzip/rubyzip.svg)](https://coveralls.io/r/rubyzip/rubyzip?branch=master)\n\nRubyzip is a ruby library for reading and writing zip files.\n\n## Important notes\n\n### Reporting security issues with this library\n\nIf you think you have found a security issue with this library, please don't submit a public issue or PR. Email me directly at hainesr@gmail.com with as much information as you can provide - steps for replication are particularly helpful if you can - and we'll get it sorted ASAP. Thank you.\n\n### Updating to version 3.0\n\nThe public API of some classes has been modernized to use named parameters for optional arguments. Please check your usage of the following Rubyzip classes:\n* `File`\n* `Entry`\n* `InputStream`\n* `OutputStream`\n\n**Please see [Updating to version 3.x](https://github.com/rubyzip/rubyzip/wiki/Updating-to-version-3.x) in the wiki for details.**\n\n## Requirements\n\nVersion 3.x requires at least Ruby 3.0.\n\nVersion 2.x requires at least Ruby 2.4, and is known to work on Ruby 3.x.\n\nIt is not recommended to use any versions of Rubyzip earlier than 2.3 due to security issues.\n\n## Installation\n\nRubyzip is available on RubyGems:\n\n```\ngem install rubyzip\n```\n\nOr in your Gemfile:\n\n```ruby\ngem 'rubyzip', require: 'zip' # For versions before 3.4.\ngem 'rubyzip'                 # For version 3.4 and after.\n```\n\nFrom version 3.4 onwards, you can `require` either 'zip' or 'rubyzip' to use this library. Before version 3.4 you need to `require 'zip'` explicitly.\n\n## Usage\n\n### Basic zip archive creation\n\n```ruby\nrequire 'rubygems'\nrequire 'zip'\n\nfolder = \"Users/me/Desktop/stuff_to_zip\"\ninput_filenames = ['image.jpg', 'description.txt', 'stats.csv']\n\nzipfile_name = \"/Users/me/Desktop/archive.zip\"\n\nZip::File.open(zipfile_name, create: true) do |zipfile|\n  input_filenames.each do |filename|\n    # Two arguments:\n    # - The name of the file as it will appear in the archive\n    # - The original file, including the path to find it\n    zipfile.add(filename, File.join(folder, filename))\n  end\n  zipfile.get_output_stream(\"myFile\") { |f| f.write \"myFile contains just this\" }\nend\n```\n\n### Creating a Zip file with `Zip::OutputStream`\n\n```ruby\nrequire 'rubygems'\nrequire 'zip'\n\nZip::OutputStream.open('archive.zip') do |zos|\n  # Quick.\n  zos.put_next_entry('greeting.txt')\n  zos \u003c\u003c 'Hello, World!'\n\n  # More control.\n  # You MUST NOT make any calls on your `Entry` after calling `put_next_entry`.\n  entry = Zip::Entry.new(nil, 'parting.txt')\n  entry.atime = Time.now\n  zos.put_next_entry(entry)\n  zos.write('TTFN')\nend\n```\n\nYou can generate a Zip archive in memory using `Zip::OutputStream.write_buffer`.\n\n### Suppressing extra fields\n\nIf you wish to suppress extra fields from being added to your entries, you can do so by passing the `suppress_extra_fields` parameter to any of the archive opening calls within `Zip::File` or `Zip::OutputStream`, e.g.:\n\n```ruby\n# Suppress all extra fields.\nZip::File.open('archive.zip', create: true, suppress_extra_fields: true)\nZip::OutputStream.open('archive.zip', suppress_extra_fields: true)\n\n# Suppress an individual extra field.\nZip::File.open('archive.zip', create: true, suppress_extra_fields: :zip64)\nZip::OutputStream.open('archive.zip', suppress_extra_fields: :zip64)\n\n# Suppress multiple extra fields.\nZip::File.open('archive.zip', create: true, suppress_extra_fields: [:ntfs, :zip64])\nZip::OutputStream.open('archive.zip', suppress_extra_fields: [:ntfs, :zip64])\n```\n\nNote that there are some extra fields that cannot be suppressed at all (e.g. `:aes`), and some which will only be suppressed if it is safe to do so (e.g. `:zip64`).\n\n### Zipping a directory recursively\n\n`Zip::File#add_recursive` adds the contents of a directory (not the directory itself) to an archive, recursing into subdirectories:\n\n```ruby\nZip::File.open('archive.zip', create: true) do |zipfile|\n  zipfile.add_recursive('/path/to/directory')\nend\n```\n\nPass `prefix:` (default `''`) to nest the contents under a prefix inside the archive, and `max_depth:` (default `16`) to limit how many directory levels are walked. Symlinks are always skipped (ignored, with a warning), rather than followed or added.\n\nFor more manual control, here is a hand-rolled version of the same thing:\n\n```ruby\nrequire 'zip'\n\n# This is a simple example which uses rubyzip to\n# recursively generate a zip file from the contents of\n# a specified directory. The directory itself is not\n# included in the archive, rather just its contents.\n#\n# Usage:\n#   directory_to_zip = \"/tmp/input\"\n#   output_file = \"/tmp/out.zip\"\n#   zf = ZipFileGenerator.new(directory_to_zip, output_file)\n#   zf.write()\nclass ZipFileGenerator\n  # Initialize with the directory to zip and the location of the output archive.\n  def initialize(input_dir, output_file)\n    @input_dir = input_dir\n    @output_file = output_file\n  end\n\n  # Zip the input directory.\n  def write\n    entries = Dir.entries(@input_dir) - %w[. ..]\n\n    ::Zip::File.open(@output_file, create: true) do |zipfile|\n      write_entries entries, '', zipfile\n    end\n  end\n\n  private\n\n  # A helper method to make the recursion work.\n  def write_entries(entries, path, zipfile)\n    entries.each do |e|\n      zipfile_path = path == '' ? e : File.join(path, e)\n      disk_file_path = File.join(@input_dir, zipfile_path)\n\n      if File.directory? disk_file_path\n        recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)\n      else\n        put_into_archive(disk_file_path, zipfile, zipfile_path)\n      end\n    end\n  end\n\n  def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)\n    zipfile.mkdir zipfile_path\n    subdir = Dir.entries(disk_file_path) - %w[. ..]\n    write_entries subdir, zipfile_path, zipfile\n  end\n\n  def put_into_archive(disk_file_path, zipfile, zipfile_path)\n    zipfile.add(zipfile_path, disk_file_path)\n  end\nend\n```\n\n### Save zip archive entries sorted by name\n\nTo save zip archives with their entries sorted by name (see below), set `::Zip.sort_entries` to `true`\n\n```\nVegetable/\nVegetable/bean\nVegetable/carrot\nVegetable/celery\nfruit/\nfruit/apple\nfruit/kiwi\nfruit/mango\nfruit/orange\n```\n\nOpening an existing zip file with this option set will not change the order of the entries automatically. Altering the zip file - adding an entry, renaming an entry, adding or changing the archive comment, etc - will cause the ordering to be applied when closing the file.\n\n### Default permissions of zip archives\n\nOn Posix file systems the default file permissions applied to a new archive\nare (0666 - umask), which mimics the behavior of standard tools such as `touch`.\n\nOn Windows the default file permissions are set to 0644 as suggested by the\n[Ruby File documentation](https://docs.ruby-lang.org/en/master/File.html#class-file-file-permissions).\n\nWhen modifying a zip archive the file permissions of the archive are preserved.\n\n### Reading a Zip file\n\n```ruby\nMAX_SIZE = 1024**2 # 1MiB (but of course you can increase this)\nZip::File.open('foo.zip') do |zip_file|\n  # Handle entries one by one\n  zip_file.each do |entry|\n    puts \"Extracting #{entry.name}\"\n    raise 'File too large when extracted' if entry.size \u003e MAX_SIZE\n\n    # Extract to file or directory based on name in the archive\n    entry.extract\n\n    # Read into memory\n    content = entry.get_input_stream.read\n  end\n\n  # Find specific entry\n  entry = zip_file.glob('*.csv').first\n  raise 'File too large when extracted' if entry.size \u003e MAX_SIZE\n  puts entry.get_input_stream.read\nend\n```\n\nTo extract every entry in an archive at once, preserving its directory structure, use `Zip::File#extract_all`:\n\n```ruby\nZip::File.open('foo.zip') do |zip_file|\n  zip_file.extract_all('/path/to/destination')\nend\n```\n\nAs with `extract`, existing files at the destination will raise `Zip::DestinationExistsError` unless a block is passed to resolve the conflict (see [Existing Files](#existing-files) below). Symlink entries are always skipped (ignored, with a warning), rather than extracted.\n\n### Reading a Zip file with `Zip::InputStream`\n\n`Zip::InputStream` can be used for faster reading of zip file content because it does not read the Central directory up front.\n\nThere is one exception where it can not work however, and this is if the file does not contain enough information in the local entry headers to extract an entry. This is indicated in an entry by the General Purpose Flag bit 3 being set.\n\n\u003e If bit 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the header is written. The fields in the local header are filled with zero, and the CRC-32 and size are appended in a 12-byte structure (optionally preceded by a 4-byte signature) immediately after the compressed data.\n\nIf `Zip::InputStream` finds such an entry in the zip archive it will raise an exception (`Zip::StreamingError`).\n\n`Zip::InputStream` is not designed to be used for random access in a zip file. When performing any operations on an entry that you are accessing via `Zip::InputStream#get_next_entry` then you should complete any such operations before the next call to `get_next_entry`.\n\n```ruby\nZip::InputStream.open('file.zip') do |zip_stream|\n  while entry = zip_stream.get_next_entry\n    # All required operations on `entry` go here.\n  end\nend # The `InputStream` is closed at the end of the block.\n```\n\nAny attempt to move about in a zip file opened with `Zip::InputStream` could result in the incorrect entry being accessed and/or Zlib buffer errors. If you need random access in a zip file, use `Zip::File`.\n\n### Encryption and Password Protection (experimental)\n\nRubyzip supports reading and writing zip files with AES encryption (reading: version 3.1 and later; writing: version 3.7 and later), and reading and writing zip files with traditional zip encryption (a.k.a. \"ZipCrypto\"). Encryption is currently only available with the stream API, with either files or buffers, e.g.:\n\n#### Version 2.x (ZipCrypto only)\n\n```ruby\n# Writing.\nenc = Zip::TraditionalEncrypter.new('password')\nbuffer = Zip::OutputStream.write_buffer(::StringIO.new(''), enc) do |output|\n  output.put_next_entry(\"my_file.txt\")\n  output.write my_data\nend\n\n# Reading.\ndec = Zip::TraditionalDecrypter.new('password')\nZip::InputStream.open(buffer, 0, dec) do |input|\n  entry = input.get_next_entry\n  puts \"Contents of '#{entry.name}':\"\n  puts input.read\nend\n```\n\n#### Version 3.x (AES and ZipCrypto)\n\n```ruby\n# Writing AES, version 3.7 and later.\nenc = Zip::AESEncrypter.new('password', Zip::AESEncryption::STRENGTH_256_BIT)\nZip::OutputStream.open('aes-encrypted-file.zip', encrypter: enc) do |output|\n  output.put_next_entry('my_file.txt')\n  output.write my_data\nend\n\n# Reading AES, version 3.1 and later.\ndec = Zip::AESDecrypter.new('password', Zip::AESEncryption::STRENGTH_256_BIT)\nZip::InputStream.open('aes-encrypted-file.zip', decrypter: dec) do |input|\n  entry = input.get_next_entry\n  puts \"Contents of '#{entry.name}':\"\n  puts input.read\nend\n\n# Writing ZipCrypto.\nenc = Zip::TraditionalEncrypter.new('password')\nbuffer = Zip::OutputStream.write_buffer(encrypter: enc) do |output|\n  output.put_next_entry(\"my_file.txt\")\n  output.write my_data\nend\n\n# Reading ZipCrypto.\ndec = Zip::TraditionalDecrypter.new('password')\nZip::InputStream.open(buffer, decrypter: dec) do |input|\n  entry = input.get_next_entry\n  puts \"Contents of '#{entry.name}':\"\n  puts input.read\nend\n```\n\n#### Passing a decrypter to an individual `Entry`\n\nYou can also decrypt an `Entry` by passing a decrypter into `Zip::Entry#get_input_stream`. This allows you to decrypt files from a Zip file with different passwords.\n\n```ruby\nZip::File.open('aes-encrypted-file.zip') do |zip|\n  entries = [['file1.txt', 'password1'], ['file2.txt', 'password2']]\n\n  entries.each do |entry_name, password|\n    entry = zip.find_entry(entry_name)\n    dec = Zip::AESDecrypter.new(password, Zip::AESEncryption::STRENGTH_256_BIT)\n    zis = entry.get_input_stream(decrypter: dec)\n\n    puts \"Contents of '#{entry.name}':\"\n    puts zis.read\n  end\nend\n```\n\n_This is an evolving feature and the interface for encryption may change in future versions._\n\n## Known issues\n\n### Modify docx file with rubyzip\n\nUse `write_buffer` instead `open`. Thanks to @jondruse\n\n```ruby\nbuffer = Zip::OutputStream.write_buffer do |out|\n  @zip_file.entries.each do |e|\n    unless [DOCUMENT_FILE_PATH, RELS_FILE_PATH].include?(e.name)\n      out.put_next_entry(e.name)\n      out.write e.get_input_stream.read\n    end\n  end\n\n  out.put_next_entry(DOCUMENT_FILE_PATH)\n  out.write xml_doc.to_xml(:indent =\u003e 0).gsub(\"\\n\",\"\")\n\n  out.put_next_entry(RELS_FILE_PATH)\n  out.write rels.to_xml(:indent =\u003e 0).gsub(\"\\n\",\"\")\nend\n\nFile.open(new_path, \"wb\") {|f| f.write(buffer.string) }\n```\n\n## Configuration\n\n### Existing Files\n\nBy default, rubyzip will not overwrite files if they already exist inside of the extracted path. To change this behavior, you may specify a configuration option like so:\n\n```ruby\nZip.on_exists_proc = true\n```\n\nIf you're using rubyzip with rails, consider placing this snippet of code in an initializer file such as `config/initializers/rubyzip.rb`\n\nAdditionally, if you want to configure rubyzip to overwrite existing files while creating a .zip file, you can do so with the following:\n\n```ruby\nZip.continue_on_exists_proc = true\n```\n\nAs of version 3.8.0, writing a second entry with the same name as one already written via `Zip::OutputStream#put_next_entry` raises `Zip::EntryExistsError` by default, instead of silently discarding the first entry's central directory record while its data remains in the archive. If you need an archive to contain multiple entries with the same name, see [Duplicate Entry Names](#duplicate-entry-names) below.\n\n### Non-ASCII Names\n\nTo store non-English filenames as UTF-8 (decoded correctly by Windows 7 or later and other modern tools), set this option:\n\n```ruby\nZip.unicode_names = true\n```\n\nSometimes file names inside zip contain non-ASCII characters. If you can assume which encoding was used for such names and want to be able to find such entries using `find_entry` then you can force assumed encoding like so:\n\n```ruby\nZip.force_entry_names_encoding = 'UTF-8'\n```\n\nAllowed encoding names are the same as accepted by `String#force_encoding`\n\n### Date Validation\n\nSome zip files might have an invalid date format, which will raise a warning. You can hide this warning with the following setting:\n\n```ruby\nZip.warn_invalid_date = false\n```\n\n### Validating Declared Number of Entries\n\nWhen reading a zip file it is potentially dangerous to trust what it tells you about how many entries it contains. A malformed zip file could claim a high number of entries in an attempt to waste internal resources, or crash the processing application.\n\nBy default rubyzip will warn if the number of declared entries is impossible based on the actual size of the Central Directory headers. You can set this check to raise an error:\n\n```ruby\nZip.validate_declared_number_of_entries = true\n```\n\nIt is likely that the default behaviour for this check will be changed to raise an error in version 4.\n\n### Entry Size Validation\n\nBy default (in rubyzip \u003e= 2.0), rubyzip's `extract` method checks that an entry's reported uncompressed size is not (significantly) smaller than its actual size. This is to help you protect your application against [zip bombs](https://en.wikipedia.org/wiki/Zip_bomb). Before `extract`ing an entry, you should check that its size is in the range you expect. For example, if your application supports processing up to 100 files at once, each up to 10MiB, your zip extraction code might look like:\n\n```ruby\nMAX_FILE_SIZE = 10 * 1024**2 # 10MiB\nMAX_FILES = 100\nZip::File.open('foo.zip') do |zip_file|\n  num_files = 0\n  zip_file.each do |entry|\n    num_files += 1 if entry.file?\n    raise 'Too many extracted files' if num_files \u003e MAX_FILES\n    raise 'File too large when extracted' if entry.size \u003e MAX_FILE_SIZE\n    entry.extract\n  end\nend\n```\n\nIf you need to extract zip files that report incorrect uncompressed sizes and you really trust them not too be too large, you can disable this setting with\n```ruby\nZip.validate_entry_sizes = false\n```\n\nNote that if you use the lower level `Zip::InputStream` interface, `rubyzip` does *not* check the entry `size`s. In this case, the caller is responsible for making sure it does not read more data than expected from the input stream.\n\n### Compression level\n\nWhen adding entries to a zip archive you can set the compression level to trade-off compressed size against compression speed. By default this is set to the same as the underlying Zlib library's default (`Zlib::DEFAULT_COMPRESSION`), which is somewhere in the middle.\n\nYou can configure the default compression level with:\n\n```ruby\nZip.default_compression = X\n```\n\nWhere X is an integer between 0 and 9, inclusive. If this option is set to 0 (`Zlib::NO_COMPRESSION`) then entries will be stored in the zip archive uncompressed. A value of 1 (`Zlib::BEST_SPEED`) gives the fastest compression and 9 (`Zlib::BEST_COMPRESSION`) gives the smallest compressed file size.\n\nThis can also be set for each archive as an option to `Zip::File`:\n\n```ruby\nZip::File.open('foo.zip', create:true, compression_level: 9) do |zip|\n  zip.add ...\nend\n```\n\n### Zip64 Support\n\nSince version 3.0, Zip64 support is enabled for writing by default. To disable it do this:\n\n```ruby\nZip.write_zip64_support = false\n```\n\nPrior to version 3.0, Zip64 support is disabled for writing by default.\n\n_NOTE_: If Zip64 write support is enabled then any extractor subsequently used may also require Zip64 support to read from the resultant archive.\n\n### Inflater chunk size\n\nWhen reading a deflated entry, rubyzip feeds the compressed data to Zlib in chunks of 4 KiB. Deflate can compress data by up to around 1000:1, so this bounds how much is inflated beyond what a single read asked for (to about 4 MiB in the worst case). Smaller values lower that bound further, at the cost of a little more overhead per byte on entries that barely compress; larger values do the opposite. To change it:\n\n```ruby\nZip.inflater_chunk_size = 1024 # Default is 4096.\n```\n\nConsider setting `Zip.inflater_chunk_size` to a higher number (e.g. 32,768) if you know your data is not highly compressible (other zip files, JPEGs, etc) and you value performance over a smaller memory footprint.\n\n### Duplicate Entry Names\n\nBy default, rubyzip only ever keeps one entry per name: adding, renaming or writing an entry whose name already exists either raises (see [Existing Files](#existing-files) above) or silently replaces the existing entry, and reading a zip that already contains duplicate names on disk keeps only the last one. Some other zip tools do allow a single archive to contain multiple entries with the same name. To read and write such archives with rubyzip, enable this setting:\n\n```ruby\nZip.allow_duplicate_entry_names = true\n```\n\nThis should be set once, at program start-up. With it enabled:\n\n* Query methods such as `Zip::File#find_entry` and `Zip::File#get_entry` return an Array of every entry matching a name (possibly empty), instead of a single entry or `nil`.\n* `Zip::File#add` and `Zip::File#rename`, given a `continue_on_exists_proc` that returns `true`, let the new entry coexist with the existing one(s) rather than replacing them.\n* `Zip::File#remove` and `Zip::File#rename`, given a bare name, act on every entry with that name. `Zip::File#get_input_stream`, `Zip::File#read` and `Zip::File#extract` act on the first match. Pass an actual `Zip::Entry` (e.g. one obtained from `#find_entry`) instead of a name to any of these to target one specific duplicate.\n* `Zip::OutputStream#put_next_entry` allows writing more than one entry with the same name instead of raising.\n* The `Zip::FileSystem` adapter (`zip.file`/`zip.dir`) always sees only the first matching entry for a given path, since it mimics Ruby's `::File`/ `::Dir` APIs, which have no way to represent more than one file per path.\n\n### Block Form\n\nYou can set multiple settings at the same time by using a block:\n\n```ruby\n  Zip.setup do |c|\n    c.on_exists_proc = true\n    c.continue_on_exists_proc = true\n    c.unicode_names = true\n    c.default_compression = Zlib::BEST_COMPRESSION\n  end\n```\n\n## Compatibility\n\nRubyzip is known to run on a number of platforms and under a number of different Ruby versions.\n\n### Version 2.4.x\n\nRubyzip 2.4 is known to work on MRI 2.4 to 3.4 on Linux and Mac, and JRuby and Truffleruby on Linux. There are known issues with Windows which have been fixed on the development branch. Please [let us know](https://github.com/rubyzip/rubyzip/pulls) if you know Rubyzip 2.4 works on a platform/Ruby combination not listed here, or [raise an issue](https://github.com/rubyzip/rubyzip/issues) if you see a failure where we think it should work.\n\n### Version 3.x\n\nPlease see the table below for what we think the current situation is. Note: an empty cell means \"unknown\", not \"does not work\".\n\n| OS/Ruby | 3.0 | 3.1 | 3.2 | 3.3 | 3.4 | 4.0 | Head | JRuby 10.0.1.0 | JRuby Head | Truffleruby 34.0.1 | Truffleruby Head |\n|---------|-----|-----|-----|-----|-----|-----|------|----------------|------------|-------------------|------------------|\n|Ubuntu 24.04| CI | CI | CI | CI | CI | CI | ci | CI | ci | CI | ci |\n|Mac OS 15.7.7| CI | x | x | CI | CI | CI | ci | x |  | x |  |\n|Windows Server 2022| CI |  |  |  |  |  |  |  |  |  |  |\n|Windows Server 2025|  |  |  | CI |  | CI | CI\u0026nbsp;mswin\u003c/br\u003eCI\u0026nbsp;ucrt |  |  |  |  |\n\nKey: `CI` - tested in CI, should work; `ci` - tested in CI, might fail; `x` - known working; `o` - known failing.\n\nRubies 3.1+ are also tested separately with YJIT turned on (Ubuntu and Mac OS).\n\nSee [the Actions tab](https://github.com/rubyzip/rubyzip/actions) in GitHub for full details.\n\nPlease [raise a PR](https://github.com/rubyzip/rubyzip/pulls) if you know Rubyzip works on a platform/Ruby combination not listed here, or [raise an issue](https://github.com/rubyzip/rubyzip/issues) if you see a failure where we think it should work.\n\n## Developing\n\nInstall the dependencies:\n\n```shell\nbundle install\n```\n\nRun the tests with `rake`:\n\n```shell\nrake\n```\n\nPlease also run `rubocop` over your changes.\n\nOur CI runs on [GitHub Actions](https://github.com/rubyzip/rubyzip/actions). Please note that `rubocop` is run as part of the CI configuration and will fail a build if errors are found.\n\n## Website and Project Home\n\nhttp://github.com/rubyzip/rubyzip\n\nhttp://rdoc.info/github/rubyzip/rubyzip/master/frames\n\n## Authors\n\nSee https://github.com/rubyzip/rubyzip/graphs/contributors for a comprehensive list.\n\n### Current maintainers\n\n* Robert Haines (@hainesr)\n* John Lees-Miller (@jdleesmiller)\n* Oleksandr Simonov (@simonoff)\n\n### Original author\n\n* Thomas Sondergaard\n\n## License\n\nRubyzip is distributed under the same license as Ruby. In practice this means you can use it under the terms of the Ruby License or the 2-Clause BSD License. See https://www.ruby-lang.org/en/about/license.txt and LICENSE.md for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyzip%2Frubyzip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyzip%2Frubyzip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyzip%2Frubyzip/lists"}