MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / readZipEntries

Function readZipEntries

packages/node-sdk/test/local-logging.test.ts:67–100  ·  view source on GitHub ↗
(buf: Buffer)

Source from the content-addressed store, hash-verified

65}
66
67function readZipEntries(buf: Buffer): Map<string, Buffer> {
68 let eocd = -1;
69 for (let i = buf.length - 22; i >= Math.max(0, buf.length - 65557); i--) {
70 if (buf.readUInt32LE(i) === 0x06054b50) {
71 eocd = i;
72 break;
73 }
74 }
75 if (eocd === -1) throw new Error('zip eocd not found');
76 const entryCount = buf.readUInt16LE(eocd + 10);
77 const cdOffset = buf.readUInt32LE(eocd + 16);
78 const entries = new Map<string, Buffer>();
79 let pos = cdOffset;
80 for (let i = 0; i < entryCount; i++) {
81 if (buf.readUInt32LE(pos) !== 0x02014b50) throw new Error('bad cd entry');
82 const method = buf.readUInt16LE(pos + 10);
83 const compressedSize = buf.readUInt32LE(pos + 20);
84 const fnameLen = buf.readUInt16LE(pos + 28);
85 const extraLen = buf.readUInt16LE(pos + 30);
86 const commentLen = buf.readUInt16LE(pos + 32);
87 const lfhOffset = buf.readUInt32LE(pos + 42);
88 const filename = buf.toString('utf8', pos + 46, pos + 46 + fnameLen);
89 if (buf.readUInt32LE(lfhOffset) !== 0x04034b50) throw new Error('bad lfh');
90 const lfhFnameLen = buf.readUInt16LE(lfhOffset + 26);
91 const lfhExtraLen = buf.readUInt16LE(lfhOffset + 28);
92 const dataStart = lfhOffset + 30 + lfhFnameLen + lfhExtraLen;
93 const compressed = buf.subarray(dataStart, dataStart + compressedSize);
94 const data = method === 0 ? compressed : method === 8 ? zlib.inflateRawSync(compressed) : null;
95 if (data === null) throw new Error('unsupported compression');
96 entries.set(filename, data);
97 pos += 46 + fnameLen + extraLen + commentLen;
98 }
99 return entries;
100}
101
102describe('Local logging — harness integration', () => {
103 it('writes session-tagged entries to session log only and untagged entries to global', async () => {

Callers 1

Calls 2

toStringMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected