• Joe Tsai's avatar
    archive/tar: centralize all information about tar header format · 30bfafc3
    Joe Tsai authored
    The Reader and Writer have hard-coded constants regarding the
    offsets and lengths of certain fields in the tar format sprinkled
    all over. This makes it harder to verify that the offsets are
    correct since a reviewer would need to search for them throughout
    the code. Instead, all information about the layout of header
    fields should be centralized in one single file. This has the
    advantage of being both centralized, and also acting as a form
    of documentation about the header struct format.
    
    This method was chosen over using "encoding/binary" since that
    method would cause an allocation of a header struct every time
    binary.Read was called. This method causes zero allocations and
    its logic is no longer than if structs were declared.
    
    Updates #12594
    
    Change-Id: Ic7a0565d2a2cd95d955547ace3b6dea2b57fab34
    Reviewed-on: https://go-review.googlesource.com/14669Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    30bfafc3
writer.go 11.1 KB