Class: CrxUnpack
- Inherits:
-
Object
- Object
- CrxUnpack
- Defined in:
- lib/crx_unpack.rb,
lib/crx_unpack/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#magic ⇒ Object
readonly
Returns the value of attribute magic.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
-
#public_key_length ⇒ Object
readonly
Returns the value of attribute public_key_length.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
-
#signature_length ⇒ Object
readonly
Returns the value of attribute signature_length.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#zip ⇒ Object
readonly
Returns the value of attribute zip.
Class Method Summary collapse
- .unpack(data) ⇒ Object
- .unpack_contents(data, dest, leave_zip_file = false) ⇒ Object
- .unpack_contents_from_file(file, dest, leave_zip_file = false) ⇒ Object
- .unpack_contents_from_io(io, dest, leave_zip_file = false) ⇒ Object
- .unpack_from_file(file) ⇒ Object
- .unpack_from_io(io) ⇒ Object
Instance Method Summary collapse
- #unpack(data) ⇒ Object
- #unpack_contents(data, dest, leave_zip_file = false) ⇒ Object
- #unpack_contents_from_file(file, dest, leave_zip_file = false) ⇒ Object
- #unpack_contents_from_io(io, dest, leave_zip_file = false) ⇒ Object
- #unpack_from_file(file) ⇒ Object
- #unpack_from_io(io) ⇒ Object
Instance Attribute Details
#magic ⇒ Object (readonly)
Returns the value of attribute magic.
6 7 8 |
# File 'lib/crx_unpack.rb', line 6 def magic @magic end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
6 7 8 |
# File 'lib/crx_unpack.rb', line 6 def public_key @public_key end |
#public_key_length ⇒ Object (readonly)
Returns the value of attribute public_key_length.
6 7 8 |
# File 'lib/crx_unpack.rb', line 6 def public_key_length @public_key_length end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
6 7 8 |
# File 'lib/crx_unpack.rb', line 6 def signature @signature end |
#signature_length ⇒ Object (readonly)
Returns the value of attribute signature_length.
6 7 8 |
# File 'lib/crx_unpack.rb', line 6 def signature_length @signature_length end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/crx_unpack.rb', line 6 def version @version end |
#zip ⇒ Object (readonly)
Returns the value of attribute zip.
6 7 8 |
# File 'lib/crx_unpack.rb', line 6 def zip @zip end |
Class Method Details
.unpack(data) ⇒ Object
61 62 63 |
# File 'lib/crx_unpack.rb', line 61 def unpack(data) new.unpack(data) end |
.unpack_contents(data, dest, leave_zip_file = false) ⇒ Object
73 74 75 |
# File 'lib/crx_unpack.rb', line 73 def unpack_contents(data, dest, leave_zip_file=false) new.unpack_contents(data, dest, leave_zip_file) end |
.unpack_contents_from_file(file, dest, leave_zip_file = false) ⇒ Object
81 82 83 |
# File 'lib/crx_unpack.rb', line 81 def unpack_contents_from_file(file, dest, leave_zip_file=false) new.unpack_contents_from_file(file, dest, leave_zip_file) end |
.unpack_contents_from_io(io, dest, leave_zip_file = false) ⇒ Object
77 78 79 |
# File 'lib/crx_unpack.rb', line 77 def unpack_contents_from_io(io, dest, leave_zip_file=false) new.unpack_contents_from_io(io, dest, leave_zip_file) end |
.unpack_from_file(file) ⇒ Object
69 70 71 |
# File 'lib/crx_unpack.rb', line 69 def unpack_from_file(file) new.unpack_from_file(file) end |
.unpack_from_io(io) ⇒ Object
65 66 67 |
# File 'lib/crx_unpack.rb', line 65 def unpack_from_io(io) new.unpack_from_io(io) end |
Instance Method Details
#unpack(data) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/crx_unpack.rb', line 8 def unpack(data) @magic = data.slice!(0, 4) @version = data.slice!(0, 4) @public_key_length = data.slice!(0, 4).unpack("i*")[0] @signature_length = data.slice!(0, 4).unpack("i*")[0] @public_key = data.slice!(0, public_key_length) @signature = data.slice!(0, signature_length) @zip = data self end |
#unpack_contents(data, dest, leave_zip_file = false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/crx_unpack.rb', line 28 def unpack_contents(data, dest, leave_zip_file=false) unpack(data) dest = File.(dest) unless Dir.exists?(dest) Dir.mkdir(dest) end Dir.chdir(dest) do zip_file = 'extension.zip' open(zip_file, 'wb'){ |f| f.write zip } $stdout.reopen('/dev/null') # Ignore `Invalid date/time in zip entry' warning zf = Zip::ZipFile.new(zip_file) zf.each do |entry| zf.extract(entry, entry.to_s) end $stdout.flush $stdout.reopen(STDERR) File.unlink(zip_file) unless leave_zip_file end end |
#unpack_contents_from_file(file, dest, leave_zip_file = false) ⇒ Object
56 57 58 |
# File 'lib/crx_unpack.rb', line 56 def unpack_contents_from_file(file, dest, leave_zip_file=false) unpack_contents(open(file, 'rb').read, dest, leave_zip_file) end |
#unpack_contents_from_io(io, dest, leave_zip_file = false) ⇒ Object
51 52 53 54 |
# File 'lib/crx_unpack.rb', line 51 def unpack_contents_from_io(io, dest, leave_zip_file=false) io.binmode? || io.binmode unpack_contents(io.read, dest, leave_zip_file) end |
#unpack_from_file(file) ⇒ Object
24 25 26 |
# File 'lib/crx_unpack.rb', line 24 def unpack_from_file(file) unpack(open(file, 'rb').read) end |
#unpack_from_io(io) ⇒ Object
19 20 21 22 |
# File 'lib/crx_unpack.rb', line 19 def unpack_from_io(io) io.binmode? || io.binmode unpack(io.read) end |