(block: Uint8Array)
| 840 | } |
| 841 | |
| 842 | const parseHeader = (block: Uint8Array): RawHeader => { |
| 843 | if (!verifyChecksum(block)) { |
| 844 | throw invalidHeader("header checksum mismatch") |
| 845 | } |
| 846 | const isUstar = hasBytes(block, 257, USTAR_MAGIC) |
| 847 | const isGnu = !isUstar && hasBytes(block, 257, GNU_MAGIC) |
| 848 | const header: RawHeader = { |
| 849 | typeflag: String.fromCharCode(block[156]), |
| 850 | path: readString(block, 0, 100), |
| 851 | linkTarget: readString(block, 157, 100), |
| 852 | size: readUnsigned(block, 124, 12, "size"), |
| 853 | mode: readUnsigned(block, 100, 8, "mode"), |
| 854 | uid: readUnsigned(block, 108, 8, "uid"), |
| 855 | gid: readUnsigned(block, 116, 8, "gid"), |
| 856 | mtimeMillis: readNumber(block, 136, 12) * 1000, |
| 857 | uname: "", |
| 858 | gname: "", |
| 859 | devMajor: 0, |
| 860 | devMinor: 0 |
| 861 | } |
| 862 | if (!isUstar && !isGnu) return header |
| 863 | header.uname = readString(block, 265, 32) |
| 864 | header.gname = readString(block, 297, 32) |
| 865 | header.devMajor = readUnsigned(block, 329, 8, "devMajor") |
| 866 | header.devMinor = readUnsigned(block, 337, 8, "devMinor") |
| 867 | if (isUstar) { |
| 868 | // star archives end the block with "tar\0" and keep times after a shorter prefix |
| 869 | const prefix = hasBytes(block, 508, STAR_TRAILER) ? readString(block, 345, 131) : readString(block, 345, 155) |
| 870 | if (prefix.length > 0) header.path = `${prefix}/${header.path}` |
| 871 | } |
| 872 | return header |
| 873 | } |
| 874 | |
| 875 | const MAX_OCTAL_7 = 0o7777777 // 8-byte numeric fields |
| 876 | const MAX_OCTAL_11 = 0o77777777777 // 12-byte numeric fields |
no test coverage detected