Class: File
- Defined in:
- lib/ronin/extensions/file.rb,
lib/ronin/formatting/extensions/binary/file.rb,
lib/ronin/formatting/extensions/digest/file.rb
Overview
Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
This file is part of Ronin Support.
Ronin Support is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ronin Support is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with Ronin Support. If not, see http://www.gnu.org/licenses/.
Class Method Summary collapse
-
.each_line(path) {|line| ... } ⇒ Enumerator
Reads each line from the file.
-
.each_row(path, separator = /\s+/) {|row| ... } ⇒ Enumerator
Reads each row from the file.
-
.escape_path(path) ⇒ String
Escapes a path.
-
.md5(path) ⇒ String
Calculates the MD5 checksum of a file.
-
.sha1(path) ⇒ String
Calculates the SHA1 checksum of a file.
- .sha128(path) ⇒ Object
- .sha2(path) ⇒ Object
-
.sha256(path) ⇒ String
Calculates the SHA256 checksum of a file.
- .sha5(path) ⇒ Object
-
.sha512(path) ⇒ String
Calculates the SHA512 checksum of a file.
-
.unhexdump(path, options = {}) ⇒ String
Converts a hexdump file to it's original binary data.
-
.write(path, data) ⇒ nil
Writes the given data to a specified path.
Class Method Details
.each_line(path) {|line| ... } ⇒ Enumerator
Reads each line from the file.
46 47 48 49 50 51 52 |
# File 'lib/ronin/extensions/file.rb', line 46 def File.each_line(path) return enum_for(:each_line,path) unless block_given? File.open(path) do |file| file.each_line { |line| yield line.chomp } end end |
.each_row(path, separator = /\s+/) {|row| ... } ⇒ Enumerator
Reads each row from the file.
81 82 83 84 85 |
# File 'lib/ronin/extensions/file.rb', line 81 def File.each_row(path,separator=/\s+/) return enum_for(:each_row,path,separator) unless block_given? File.each_line(path) { |line| yield line.split(separator) } end |
.escape_path(path) ⇒ String
Escapes a path.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ronin/extensions/file.rb', line 118 def File.escape_path(path) path = path.to_s # remove any \0 characters first path.tr!("\0",'') # remove any home-dir expansions path.gsub!('~',"\\~") path = File.(File.join('/',path)) # remove the leading slash return path[1..-1] end |
.md5(path) ⇒ String
Calculates the MD5 checksum of a file.
41 42 43 |
# File 'lib/ronin/formatting/extensions/digest/file.rb', line 41 def File.md5(path) Digest::MD5.file(path).hexdigest end |
.sha1(path) ⇒ String
Calculates the SHA1 checksum of a file.
60 61 62 |
# File 'lib/ronin/formatting/extensions/digest/file.rb', line 60 def File.sha1(path) Digest::SHA1.file(path).hexdigest end |
.sha128(path) ⇒ Object
69 70 71 |
# File 'lib/ronin/formatting/extensions/digest/file.rb', line 69 def File.sha128(path) File.sha1(path) end |
.sha2(path) ⇒ Object
97 98 99 |
# File 'lib/ronin/formatting/extensions/digest/file.rb', line 97 def File.sha2(path) File.sha256(path) end |
.sha256(path) ⇒ String
Calculates the SHA256 checksum of a file.
88 89 90 |
# File 'lib/ronin/formatting/extensions/digest/file.rb', line 88 def File.sha256(path) Digest::SHA256.file(path).hexdigest end |
.sha5(path) ⇒ Object
125 126 127 |
# File 'lib/ronin/formatting/extensions/digest/file.rb', line 125 def File.sha5(path) File.sha512(path) end |
.sha512(path) ⇒ String
Calculates the SHA512 checksum of a file.
116 117 118 |
# File 'lib/ronin/formatting/extensions/digest/file.rb', line 116 def File.sha512(path) Digest::SHA512.file(path).hexdigest end |