MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / create_test_zip_stored

Function create_test_zip_stored

tests/test_cli.c:1279–1351  ·  view source on GitHub ↗

Build a minimal zip file with one stored (uncompressed) entry. */

Source from the content-addressed store, hash-verified

1277
1278/* Build a minimal zip file with one stored (uncompressed) entry. */
1279static unsigned char *create_test_zip_stored(const char *filename, const unsigned char *content,
1280 int content_len, int *out_len) {
1281 /* Local file header (30 bytes) + filename + content + central dir + EOCD */
1282 int name_len = (int)strlen(filename);
1283 int local_hdr_sz = 30 + name_len;
1284 int cd_hdr_sz = 46 + name_len;
1285 int eocd_sz = 22;
1286 int total = local_hdr_sz + content_len + cd_hdr_sz + eocd_sz;
1287 unsigned char *zip = calloc(1, (size_t)total);
1288 if (!zip)
1289 return NULL;
1290 int pos = 0;
1291
1292 /* Local file header */
1293 zip[pos] = 0x50;
1294 zip[pos + 1] = 0x4B;
1295 zip[pos + 2] = 0x03;
1296 zip[pos + 3] = 0x04; /* signature */
1297 zip[pos + 4] = 20;
1298 zip[pos + 5] = 0; /* version needed = 2.0 */
1299 zip[pos + 8] = 0;
1300 zip[pos + 9] = 0; /* compression = stored */
1301 zip[pos + 18] = (unsigned char)(content_len & 0xFF);
1302 zip[pos + 19] = (unsigned char)((content_len >> 8) & 0xFF);
1303 zip[pos + 20] = (unsigned char)((content_len >> 16) & 0xFF);
1304 zip[pos + 21] = (unsigned char)((content_len >> 24) & 0xFF);
1305 zip[pos + 22] = zip[pos + 18];
1306 zip[pos + 23] = zip[pos + 19];
1307 zip[pos + 24] = zip[pos + 20];
1308 zip[pos + 25] = zip[pos + 21];
1309 zip[pos + 26] = (unsigned char)(name_len & 0xFF);
1310 zip[pos + 27] = (unsigned char)((name_len >> 8) & 0xFF);
1311 memcpy(zip + pos + 30, filename, (size_t)name_len);
1312 pos += 30 + name_len;
1313 memcpy(zip + pos, content, (size_t)content_len);
1314 pos += content_len;
1315
1316 int cd_start = pos;
1317 /* Central directory header */
1318 zip[pos] = 0x50;
1319 zip[pos + 1] = 0x4B;
1320 zip[pos + 2] = 0x01;
1321 zip[pos + 3] = 0x02;
1322 zip[pos + 10] = 0;
1323 zip[pos + 11] = 0; /* compression = stored */
1324 zip[pos + 20] = (unsigned char)(content_len & 0xFF);
1325 zip[pos + 21] = (unsigned char)((content_len >> 8) & 0xFF);
1326 zip[pos + 22] = (unsigned char)((content_len >> 16) & 0xFF);
1327 zip[pos + 23] = (unsigned char)((content_len >> 24) & 0xFF);
1328 zip[pos + 24] = zip[pos + 20];
1329 zip[pos + 25] = zip[pos + 21];
1330 zip[pos + 26] = zip[pos + 22];
1331 zip[pos + 27] = zip[pos + 23];
1332 zip[pos + 28] = (unsigned char)(name_len & 0xFF);
1333 zip[pos + 29] = (unsigned char)((name_len >> 8) & 0xFF);
1334 pos += 46 + name_len;
1335
1336 /* EOCD */

Callers 1

test_cli.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected