MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseHeader

Function parseHeader

packages/effect/src/encoding/Tar.ts:842–873  ·  view source on GitHub ↗
(block: Uint8Array)

Source from the content-addressed store, hash-verified

840}
841
842const 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
875const MAX_OCTAL_7 = 0o7777777 // 8-byte numeric fields
876const MAX_OCTAL_11 = 0o77777777777 // 12-byte numeric fields

Callers 1

advanceMethod · 0.70

Calls 6

verifyChecksumFunction · 0.85
hasBytesFunction · 0.85
readUnsignedFunction · 0.85
invalidHeaderFunction · 0.70
readStringFunction · 0.70
readNumberFunction · 0.70

Tested by

no test coverage detected