Class: PackfileReader::PackfileHeader
- Inherits:
-
Object
- Object
- PackfileReader::PackfileHeader
- Defined in:
- lib/packfile_reader/packfile_header.rb
Overview
Defines a class for the HEADER portion of a git packfile From: git-scm.com/docs/pack-format
A header appears at the beginning and consists of the following:
4-byte signature:
The signature is: {'P', 'A', 'C', 'K'}
4-byte version number (network byte order):
Git currently accepts version number 2 or 3 but generates version 2 only.
4-byte number of objects contained in the pack (network byte order)
Observation: we cannot have more than 4G versions ;-) and more than 4G objects in a pack.
Instance Attribute Summary collapse
-
#n_entries ⇒ Object
readonly
how many objects in the packfile.
-
#sign ⇒ Object
readonly
signature (must be PACK).
-
#version ⇒ Object
readonly
version of the packfile.
Instance Method Summary collapse
-
#initialize(packfile_io) ⇒ PackfileHeader
constructor
Creates a new PackfileHeader instance reading data from the beginning of a packfile.
- #to_s ⇒ Object
Constructor Details
#initialize(packfile_io) ⇒ PackfileHeader
Creates a new PackfileHeader instance reading data from the beginning of a packfile. It fails if it cannot parse the data or if the signature does not match the expected ‘PACK’ string
Params:
packfile_io
-
the opened packfile handler in binary format (usually the output of File.open(‘path’, ‘rb’))
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/packfile_reader/packfile_header.rb', line 28 def initialize(packfile_io) begin go_to_start(packfile_io) @sign = parse_sign(packfile_io) @version = parse_version(packfile_io) @n_entries = parse_n_entries(packfile_io) rescue raise 'Invalid packfile. Cannot parse header' end raise "Invalid signature. Got '#{@sign}' expected 'PACK'" unless @sign == 'PACK' end |
Instance Attribute Details
#n_entries ⇒ Object (readonly)
how many objects in the packfile
20 21 22 |
# File 'lib/packfile_reader/packfile_header.rb', line 20 def n_entries @n_entries end |
#sign ⇒ Object (readonly)
signature (must be PACK)
19 20 21 |
# File 'lib/packfile_reader/packfile_header.rb', line 19 def sign @sign end |
#version ⇒ Object (readonly)
version of the packfile
18 19 20 |
# File 'lib/packfile_reader/packfile_header.rb', line 18 def version @version end |
Instance Method Details
#to_s ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/packfile_reader/packfile_header.rb', line 40 def to_s <<~EOS.strip Packfile Headers - Signature: #{@sign} - Version: #{@version} - Entries: #{@n_entries} EOS end |