header.to_summary_string: added human-readable size.
This commit is contained in:
parent
8d3a9242e3
commit
60b2e6d9ff
1 changed files with 19 additions and 1 deletions
|
@ -57,6 +57,7 @@ class Header < BinData::Record
|
||||||
return r.join("\n")
|
return r.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def to_summary_string
|
def to_summary_string
|
||||||
r = []
|
r = []
|
||||||
r << " Software : %s (%s)" % [self.progname_str,self.version_str]
|
r << " Software : %s (%s)" % [self.progname_str,self.version_str]
|
||||||
|
@ -64,7 +65,24 @@ class Header < BinData::Record
|
||||||
r << "Filename str : %s" % self.filename_str
|
r << "Filename str : %s" % self.filename_str
|
||||||
r << " md5 : %s" % ( self.md5 ? 'enabled' : 'disabled' )
|
r << " md5 : %s" % ( self.md5 ? 'enabled' : 'disabled' )
|
||||||
r << " Filecount : %d" % self.filecount
|
r << " Filecount : %d" % self.filecount
|
||||||
r << " Filesize : %s" % self.filesize
|
r << " Filesize : %s" % _readable_file_size( self.filesize, 2 )
|
||||||
return r.join("\n")
|
return r.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
GIGA_SIZE = 1073741824.0
|
||||||
|
MEGA_SIZE = 1048576.0
|
||||||
|
KILO_SIZE = 1024.0
|
||||||
|
def _readable_file_size size, precision
|
||||||
|
|
||||||
|
case
|
||||||
|
when size == 1 : "1 Byte"
|
||||||
|
when size < KILO_SIZE : "%d Bytes" % size
|
||||||
|
when size < MEGA_SIZE : "%.#{precision}f KB" % (size / KILO_SIZE)
|
||||||
|
when size < GIGA_SIZE : "%.#{precision}f MB" % (size / MEGA_SIZE)
|
||||||
|
else "%.#{precision}f GB" % (size / GIGA_SIZE)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue