| 
									
										
										
										
											2003-08-21 21:24:10 +08:00
										 |  |  | #!/usr/bin/env ruby | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:27:44 +08:00
										 |  |  | $: << '../lib' | 
					
						
							| 
									
										
										
										
											2003-08-21 21:24:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-21 21:54:32 +08:00
										 |  |  | require 'zip/zipfilesystem' | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 03:58:35 +08:00
										 |  |  | File.delete(EXAMPLE_ZIP) if File.exist?(EXAMPLE_ZIP) | 
					
						
							| 
									
										
										
										
											2003-08-21 21:24:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:10:37 +08:00
										 |  |  | Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) 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. |