|
1 | 1 | import { afterEach, beforeEach, describe, expect, test } from 'bun:test'; |
2 | 2 | import fs from 'fs'; |
| 3 | +import { npm, yarn } from 'global-dirs'; |
3 | 4 | import os from 'os'; |
4 | 5 | import path from 'path'; |
5 | | -import { npm, yarn } from 'global-dirs'; |
6 | 6 | import { ZipFile as YazlZipFile } from 'yazl'; |
7 | 7 | import { diffCommands, enumZipEntries, readEntry } from '../src/diff'; |
8 | 8 | import type { CommandContext } from '../src/types'; |
| 9 | +import { readEntryPrefix } from '../src/utils/zip-entries'; |
9 | 10 |
|
10 | 11 | const pngPrefix = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]); |
11 | 12 | const hermesBytecodePrefix = Buffer.from([ |
@@ -292,6 +293,23 @@ describe('diff commands', () => { |
292 | 293 | expect(result.files['extra/new.txt']?.toString('utf-8')).toBe('new-file'); |
293 | 294 | }); |
294 | 295 |
|
| 296 | + test('readEntryPrefix stops large zip entries without surfacing destroy errors', async () => { |
| 297 | + const zipPath = path.join(tempRoot, 'large-entry.ppk'); |
| 298 | + const payload = Buffer.alloc(256, 'x'); |
| 299 | + await createZip(zipPath, { |
| 300 | + 'large-entry.bin': payload, |
| 301 | + }); |
| 302 | + |
| 303 | + let prefix: Buffer | undefined; |
| 304 | + await enumZipEntries(zipPath, async (entry, zipFile) => { |
| 305 | + if (entry.fileName === 'large-entry.bin') { |
| 306 | + prefix = await readEntryPrefix(entry, zipFile, 64); |
| 307 | + } |
| 308 | + }); |
| 309 | + |
| 310 | + expect(prefix).toEqual(payload.subarray(0, 64)); |
| 311 | + }); |
| 312 | + |
295 | 313 | test('diffFromApk throws when origin package bundle is missing', async () => { |
296 | 314 | const originPath = path.join(tempRoot, 'origin-missing-bundle.apk'); |
297 | 315 | const nextPath = path.join(tempRoot, 'next-for-apk.ppk'); |
|
0 commit comments