-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtar_bz2.rb
executable file
·37 lines (30 loc) · 860 Bytes
/
tar_bz2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/ruby
require 'rubygems'
require 'libarchive'
require File.join(File.dirname(__FILE__), 'profile_tools')
pt = ProfileTools.new
#-------------------------
# Bzip a file
#-------------------------
fn = ARGV[0]
if not (File.exists?(fn))
puts "File does not exist: " + fn
exit 1
end
pt.show_mem("Have not started yet")
Archive.write_open_filename("#{fn}.tar.bz2", Archive::COMPRESSION_BZIP2, Archive::FORMAT_TAR) do |ar|
pt.show_mem("Opened archive for writing: #{fn}.tar.bz2")
ar.new_entry do |entry|
pt.show_mem("About to add entry: #{fn}")
entry.copy_stat(fn)
entry.pathname = fn
ar.write_header(entry)
open(fn) do |f|
pt.show_mem("Opened file: #{fn}")
ar.write_data { f.read(1024) }
end
pt.show_mem("Closed file: #{fn}")
end
pt.show_mem("Finished with entry: #{fn}")
end
pt.show_mem("Done")