Class: Bayonetta::PKZFile
- Inherits:
-
LibBin::Structure
- Object
- LibBin::Structure
- Bayonetta::PKZFile
show all
- Defined in:
- lib/bayonetta/pkz.rb
Defined Under Namespace
Classes: FileDescriptor, Header
Class Method Summary
collapse
Class Method Details
.is_big?(f) ⇒ Boolean
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/bayonetta/pkz.rb', line 29
def self.is_big?(f)
f.rewind
block = lambda { |int64|
id = f.read(4)
raise "Invalid id #{id.inspect}!" if id != "pkzl".b
f.read(4)
size = f.read(8).unpack(int64).first
size == f.size
}
big = block.call("q>")
f.rewind
small = block.call("q<")
f.rewind
raise "Invalid data!" unless big ^ small
return big
end
|
.load(input_name) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/bayonetta/pkz.rb', line 46
def self.load(input_name)
if input_name.respond_to?(:read) && input_name.respond_to?(:seek)
input = input_name
else
input = File.open(input_name, "rb")
end
input_big = is_big?(input)
pkz = self::new
pkz.instance_variable_set(:@__was_big, input_big)
pkz.__load(input, input_big)
input.close unless input_name.respond_to?(:read) && input_name.respond_to?(:seek)
pkz
end
|