HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/rubygems-integration/all/gems/rubyzip-2.3.0/samples/example_filesystem.rb
#!/usr/bin/env ruby

$LOAD_PATH << '../lib'

require 'zip/filesystem'

EXAMPLE_ZIP = 'filesystem.zip'

File.delete(EXAMPLE_ZIP) if File.exist?(EXAMPLE_ZIP)

Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) do |zf|
  zf.file.open('file1.txt', 'w') { |os| os.write 'first file1.txt' }
  zf.dir.mkdir('dir1')
  zf.dir.chdir('dir1')
  zf.file.open('file1.txt', 'w') { |os| os.write 'second file1.txt' }
  puts zf.file.read('file1.txt')
  puts zf.file.read('../file1.txt')
  zf.dir.chdir('..')
  zf.file.open('file2.txt', 'w') { |os| os.write 'first file2.txt' }
  puts "Entries:                   #{zf.entries.join(', ')}"
end

Zip::File.open(EXAMPLE_ZIP) do |zf|
  puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
end

# For other examples, look at zip.rb and ziptest.rb

# Copyright (C) 2003 Thomas Sondergaard
# rubyzip is free software; you can redistribute it and/or
# modify it under the terms of the ruby license.