Class: Shy

Inherits:
Object
  • Object
show all
Defined in:
lib/shoes/shy.rb

Constant Summary collapse

VERSION =
0x0001
MAGIC =
"_shy".freeze
LAYOUT =

Force to Little Endian for all platforms

"A4vV".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#creatorObject

Returns the value of attribute creator.



18
19
20
# File 'lib/shoes/shy.rb', line 18

def creator
  @creator
end

#launchObject

Returns the value of attribute launch.



18
19
20
# File 'lib/shoes/shy.rb', line 18

def launch
  @launch
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/shoes/shy.rb', line 18

def name
  @name
end

#versionObject

Returns the value of attribute version.



18
19
20
# File 'lib/shoes/shy.rb', line 18

def version
  @version
end

Class Method Details

.__hdr__(f) ⇒ Object

Raises:

  • (IOError)


30
31
32
33
34
# File 'lib/shoes/shy.rb', line 30

def self.__hdr__(f)
  hdr = f.read(10).unpack(LAYOUT)
  raise IOError, "Invalid header" if hdr[0] != MAGIC and hdr[1] > VERSION
  YAML.load(f.read(hdr[2]))
end

.c(path, shy, d, &blk) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/shoes/shy.rb', line 68

def self.c(path, shy, d, &blk)
  path = File.expand_path(path)
  meta = shy.to_yaml
  File.open(path, "wb") do |f|
    f << [MAGIC, VERSION, meta.length].pack(LAYOUT)
    f << meta
    self.czf(f, d, &blk)
  end
end

.czf(f, d, &blk) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/shoes/shy.rb', line 91

def self.czf(f, d, &blk)
  total = du(d)
  out = Zlib::GzipWriter.new(f)
  files = ["."]
  unless File.directory? d
    files = [File.basename(d)]
    d = File.dirname(d)
  end
  Dir.chdir(d) do
    Archive::Tar::Minitar.pack(files, out, &blk)
  end
end

.du(root) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shoes/shy.rb', line 37

def self.du(root)
  size = 0
  Find.find(root) do |path|
    if FileTest.directory?(path)
      if File.basename(path)[0] == ?.
        Find.prune
      else
        next
      end
    else
      size += FileTest.size(path)
    end
  end
  size
end

.hrun(f) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/shoes/shy.rb', line 117

def self.hrun(f)
  b, i = 0, 1
  last = 65535
  while i < last
    case f.readline
    when /OLDSKIP=(\d+)/
      last = $1.to_i 
    when /FULLSIZE=(\d+)/
      b = $1.to_i
    end
    i += 1
  end
  b
end

.launchable(d) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/shoes/shy.rb', line 20

def self.launchable(d)
  if File.directory? d
    Dir["#{d}/**/*.rb"].map do |path|
      path.gsub(%r!#{Regexp::quote(d)}/!, '')
    end
  else
    [File.basename(d)]
  end
end

.md5sum(path) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/shoes/shy.rb', line 109

def self.md5sum(path)
  digest = Digest::MD5.new
  File.open(path, "rb") do |f|
    digest.update f.read(8192) until f.eof
  end
  digest.hexdigest
end

.meta(path, d = ".") ⇒ Object



53
54
55
56
57
# File 'lib/shoes/shy.rb', line 53

def self.meta(path, d = ".")
  File.open(path, 'rb') do |f|
    shy = __hdr__(f)
  end
end

.progress(total, &blk) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/shoes/shy.rb', line 78

def self.progress(total, &blk)
  if blk
    last, left = 0.0, total
    proc do |action, name, stats|
      if action == :file_progress
        left -= stats[:currinc]
        prg = 1.0 - (left.to_f / total.to_f)
        blk[name, (last = prg), left] if prg - last > 0.02
      end
    end
  end
end

.x(path, d = ".") ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/shoes/shy.rb', line 59

def self.x(path, d = ".")
  File.open(path, 'rb') do |f|
    shy = __hdr__(f)
    inp = Zlib::GzipReader.new(f)
    Archive::Tar::Minitar.unpack(inp, d)
    shy
  end
end

.xzf(f, d, &blk) ⇒ Object



104
105
106
107
# File 'lib/shoes/shy.rb', line 104

def self.xzf(f, d, &blk)
  gz = Zlib::GzipReader.new(f)
  Archive::Tar::Minitar.unpack(gz, d, &blk)
end