rubyzip/samples/example_filesystem.rb

33 lines
925 B
Ruby
Raw Normal View History

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