Module: MiniTarball::HeaderFormatter
- Defined in:
- lib/mini_tarball/header_formatter.rb
Constant Summary collapse
- PERMISSION_BITMASK =
0007777
Class Method Summary collapse
- .format_checksum(checksum) ⇒ Object
- .format_number(value, length) ⇒ Object
-
.format_permissions(value, length) ⇒ Object
Removes file type bitfields and returns file permissions as formatted number.
- .zero_pad(binary) ⇒ Object
Class Method Details
.format_checksum(checksum) ⇒ Object
25 26 27 28 29 |
# File 'lib/mini_tarball/header_formatter.rb', line 25 def self.format_checksum(checksum) length = Header::FIELDS[:checksum][:length] checksum ? format_number(checksum, length - 1) << "\0 " : " " * length end |
.format_number(value, length) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/mini_tarball/header_formatter.rb', line 11 def self.format_number(value, length) return nil if !value raise NotImplementedError.new("Negative numbers are not supported") if value.negative? fits_into_octal?(value, length) ? to_octal(value, length) : to_base256(value, length) end |
.format_permissions(value, length) ⇒ Object
Removes file type bitfields and returns file permissions as formatted number
21 22 23 |
# File 'lib/mini_tarball/header_formatter.rb', line 21 def self.(value, length) format_number(value & PERMISSION_BITMASK, length) end |
.zero_pad(binary) ⇒ Object
31 32 33 34 |
# File 'lib/mini_tarball/header_formatter.rb', line 31 def self.zero_pad(binary) padding_length = (Header::BLOCK_SIZE - binary.length) % Header::BLOCK_SIZE binary << "\0" * padding_length end |