Top Level Namespace

Defined Under Namespace

Modules: Zip64 Classes: Block, String

Instance Method Summary collapse

Instance Method Details

#find_block_type(sig) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/zip64/debug.rb', line 4

def find_block_type sig
	Zip64.constants.each do |nam|
		klass = Zip64.const_get(nam)
		if klass.respond_to?(:constants) && klass.constants.include?('SIG')
			if sig == klass::SIG
				return klass
			end
		end
	end
	nil
end

#zip_debug(arg) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/zip64/debug.rb', line 16

def zip_debug(arg)

File.open(arg, "rb") do |fp|
	until fp.eof?
		until fp.eof? or (fp.tell%2).zero?
			fp.getc
		end
		bs = fp.tell
		STDOUT.write(sprintf(".%-16i", bs))
		sig = fp.read(4).unpack('V').first
		klass = find_block_type sig

		if klass
			o = klass.read_from(fp, 1)
			o.signature = sig
			o.describe(STDOUT)

			case o
			when Zip64::LocalFileHeader
				filename = fp.read(o.filename_len)
				extra = fp.read(o.extra_field_len)

				data_len = o.data_len

				unless extra.empty?
					extra_fp = StringIO.new(extra)
					until extra_fp.eof?
						esig = extra_fp.read(2).unpack('v').first
						if eklass = find_block_type(esig)
							e = eklass.read_from(extra_fp, 1)
							e.signature = sig
							e.describe(STDOUT)
						end
					end
					#if o.data_len == Zip64::LEN64
					#	info = Zip64::Zip64ExtraField.read_from(StringIO.new(extra), 0)
					#	info.describe(STDOUT)
					#	data_len = info.data_len
					#end
				end

				data = fp.read(data_len)
				p [:filename, filename]
				p [:extra, extra]
				if data.size > 50
					data = data[0..50]+"(#{data.size} bytes, truncated)"
				end
				p [:data, data]
			when Zip64::CDFileHeader
				filename = fp.read(o.filename_len)
				extra    = fp.read(o.extra_field_len)
				comment  = fp.read(o.file_comment_len)
				p [:filename, filename]
				p [:extra, extra]
				p [:comment, comment]
			end
		else
			puts sprintf('%16s %16i', sig.to_s(16), sig) if sig
		end
	end
end

end