MCPcopy
hub / github.com/prisma/prisma / parseTarHeader

Function parseTarHeader

packages/cli/src/bootstrap/template-scaffold.ts:123–139  ·  view source on GitHub ↗
(buf: Buffer, offset: number)

Source from the content-addressed store, hash-verified

121}
122
123function parseTarHeader(buf: Buffer, offset: number): TarEntry | null {
124 const header = buf.subarray(offset, offset + 512)
125 if (header.every((b) => b === 0)) return null
126
127 const name = header.subarray(0, 100).toString('utf-8').replace(/\0.*$/, '')
128 const sizeStr = header.subarray(124, 136).toString('utf-8').replace(/\0.*$/, '').trim()
129 const typeFlag = header[156]
130 const type = typeFlag === 0 ? '0' : String.fromCharCode(typeFlag)
131 const prefix = header.subarray(345, 500).toString('utf-8').replace(/\0.*$/, '')
132
133 const fullName = prefix ? `${prefix}/${name}` : name
134 const size = sizeStr ? parseInt(sizeStr, 8) : 0
135
136 if (isNaN(size)) return null
137
138 return { name: fullName, size, type }
139}
140
141/**
142 * GitHub tarballs add a `<owner>-<repo>-<sha>/` prefix to all paths.

Callers 1

Calls 2

subarrayMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected