2003-08-21 21:24:10 +08:00
|
|
|
#!/usr/bin/env ruby
|
2021-05-24 01:24:22 +08:00
|
|
|
# frozen_string_literal: true
|
2003-08-21 21:24:10 +08:00
|
|
|
|
2019-09-27 04:46:00 +08:00
|
|
|
$LOAD_PATH << '../lib'
|
2003-08-21 21:24:10 +08:00
|
|
|
|
2016-01-08 00:03:25 +08:00
|
|
|
require 'zip/filesystem'
|
2003-08-21 21:24:10 +08:00
|
|
|
|
2015-03-21 16:27:44 +08:00
|
|
|
EXAMPLE_ZIP = 'filesystem.zip'
|
2003-08-21 21:24:10 +08:00
|
|
|
|
2024-03-02 06:14:48 +08:00
|
|
|
FileUtils.rm_f(EXAMPLE_ZIP)
|
2003-08-21 21:24:10 +08:00
|
|
|
|
2021-06-09 04:24:52 +08:00
|
|
|
Zip::File.open(EXAMPLE_ZIP, create: true) do |zf|
|
2015-03-21 16:27:44 +08:00
|
|
|
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' }
|
2003-08-21 21:24:10 +08:00
|
|
|
puts "Entries: #{zf.entries.join(', ')}"
|
2015-03-21 16:10:37 +08:00
|
|
|
end
|
2003-08-21 21:24:10 +08:00
|
|
|
|
2015-03-21 16:10:37 +08:00
|
|
|
Zip::File.open(EXAMPLE_ZIP) do |zf|
|
2003-08-21 21:24:10 +08:00
|
|
|
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
2015-03-21 16:10:37 +08:00
|
|
|
end
|
2003-08-21 21:24:10 +08:00
|
|
|
|
2003-08-21 21:24:10 +08:00
|
|
|
# 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.
|