diff --git a/Sources/TAR/TarEntryInfo.swift b/Sources/TAR/TarEntryInfo.swift index 9d140b39..18d735fc 100644 --- a/Sources/TAR/TarEntryInfo.swift +++ b/Sources/TAR/TarEntryInfo.swift @@ -91,6 +91,7 @@ public struct TarEntryInfo: ContainerEntryInfo { public let unknownExtendedHeaderRecords: [String: String]? let specialEntryType: SpecialEntryType? + let format: TarContainer.Format let hasRecognizedMagic: Bool let blockStartIndex: Int @@ -208,6 +209,16 @@ public struct TarEntryInfo: ContainerEntryInfo { self.deviceMinorNumber = nil } + if local != nil || global != nil { + self.format = .pax + } else if magic == 0x00_20_20_72_61_74_73_75 || longName != nil || longLinkName != nil { + self.format = .gnu + } else if magic == 0x3030007261747375 || magic == 0x3030207261747375 { + self.format = .ustar + } else { + self.format = .prePosix + } + // Set `name` and `linkName` to values from PAX or GNU format if possible. self.name = ((local?.path ?? global?.path) ?? longName) ?? name self.linkName = ((local?.linkpath ?? global?.linkpath) ?? longLinkName) ?? linkName