MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseZipModes

Function parseZipModes

source code/utils/dxt/zip.ts:162–205  ·  view source on GitHub ↗
(data: Uint8Array)

Source from the content-addressed store, hash-verified

160 * which is fine for marketplace zips (~3.5MB) and MCPB bundles.
161 */
162export function parseZipModes(data: Uint8Array): Record<string, number> {
163 // Buffer view for readUInt* methods — shares memory, no copy.
164 const buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength)
165 const modes: Record<string, number> = {}
166
167 // 1. Find the End of Central Directory record (sig 0x06054b50). It lives in
168 // the trailing 22 + 65535 bytes (fixed EOCD size + max comment length).
169 // Scan backwards — the EOCD is typically the last 22 bytes.
170 const minEocd = Math.max(0, buf.length - 22 - 0xffff)
171 let eocd = -1
172 for (let i = buf.length - 22; i >= minEocd; i--) {
173 if (buf.readUInt32LE(i) === 0x06054b50) {
174 eocd = i
175 break
176 }
177 }
178 if (eocd < 0) return modes // malformed — let fflate's error surface elsewhere
179
180 const entryCount = buf.readUInt16LE(eocd + 10)
181 let off = buf.readUInt32LE(eocd + 16) // central directory start offset
182
183 // 2. Walk central directory entries (sig 0x02014b50). Each entry has a
184 // 46-byte fixed header followed by variable-length name/extra/comment.
185 for (let i = 0; i < entryCount; i++) {
186 if (off + 46 > buf.length || buf.readUInt32LE(off) !== 0x02014b50) break
187 const versionMadeBy = buf.readUInt16LE(off + 4)
188 const nameLen = buf.readUInt16LE(off + 28)
189 const extraLen = buf.readUInt16LE(off + 30)
190 const commentLen = buf.readUInt16LE(off + 32)
191 const externalAttr = buf.readUInt32LE(off + 38)
192 const name = buf.toString('utf8', off + 46, off + 46 + nameLen)
193
194 // versionMadeBy high byte = host OS. 3 = Unix. For Unix zips, the high
195 // 16 bits of externalAttr hold st_mode (file type + permission bits).
196 if (versionMadeBy >> 8 === 3) {
197 const mode = (externalAttr >>> 16) & 0xffff
198 if (mode) modes[name] = mode
199 }
200
201 off += 46 + nameLen + extraLen + commentLen
202 }
203
204 return modes
205}
206
207/**
208 * Reads a zip file from disk asynchronously and unzips it.

Callers 3

extractZipToDirectoryFunction · 0.85
loadMcpbFileFunction · 0.85

Calls 2

maxMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected