Class: MiniTarball::Header
- Inherits:
-
Object
- Object
- MiniTarball::Header
- Defined in:
- lib/mini_tarball/header.rb
Constant Summary collapse
- BLOCK_SIZE =
Size of each block in the tar file in bytes
512
- TYPE_REGULAR =
bytes
"0"
- TYPE_LONG_LINK =
"L"
- FIELDS =
stree-ignore
{ name: { length: 100, type: :chars }, mode: { length: 8, type: :mode }, uid: { length: 8, type: :number }, gid: { length: 8, type: :number }, size: { length: 12, type: :number }, mtime: { length: 12, type: :number }, checksum: { length: 8, type: :checksum }, typeflag: { length: 1, type: :chars }, linkname: { length: 100, type: :chars }, magic: { length: 6, type: :chars }, version: { length: 2, type: :chars }, uname: { length: 32, type: :chars }, gname: { length: 32, type: :chars }, devmajor: { length: 8, type: :number }, devminor: { length: 8, type: :number }, prefix: { length: 155, type: :chars } }
Class Method Summary collapse
Instance Method Summary collapse
- #has_long_name? ⇒ Boolean
-
#initialize(name:, mode: 0, uid: nil, gid: nil, size: 0, mtime: 0, typeflag: TYPE_REGULAR, linkname: "", uname: nil, gname: nil) ⇒ Header
constructor
:reek:LongParameterList.
- #to_binary ⇒ Object
- #value_of(key) ⇒ Object
Constructor Details
#initialize(name:, mode: 0, uid: nil, gid: nil, size: 0, mtime: 0, typeflag: TYPE_REGULAR, linkname: "", uname: nil, gname: nil) ⇒ Header
:reek:LongParameterList
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 |
# File 'lib/mini_tarball/header.rb', line 45 def initialize( name:, mode: 0, uid: nil, gid: nil, size: 0, mtime: 0, typeflag: TYPE_REGULAR, linkname: "", uname: nil, gname: nil ) @values = { name: name, mode: mode, uid: uid, gid: gid, size: size, mtime: mtime.to_i, checksum: nil, typeflag: typeflag, linkname: linkname, magic: "ustar ", version: " ", uname: uname, gname: gname, devmajor: nil, devminor: nil, prefix: "", } end |
Class Method Details
.long_link_header(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mini_tarball/header.rb', line 31 def self.long_link_header(name) Header.new( name: "././@LongLink", mode: 0644, uid: 0, gid: 0, size: name.bytesize + 1, typeflag: TYPE_LONG_LINK, uname: "root", gname: "root", ) end |
Instance Method Details
#has_long_name? ⇒ Boolean
86 87 88 |
# File 'lib/mini_tarball/header.rb', line 86 def has_long_name? value_of(:name).bytesize > FIELDS[:name][:length] end |
#to_binary ⇒ Object
81 82 83 84 |
# File 'lib/mini_tarball/header.rb', line 81 def to_binary fields = HeaderFields.new(self) fields.to_binary end |
#value_of(key) ⇒ Object
77 78 79 |
# File 'lib/mini_tarball/header.rb', line 77 def value_of(key) @values[key] end |